• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2020 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef MODULES_VIDEO_CODING_CODECS_TEST_ENCODED_VIDEO_FRAME_PRODUCER_H_
12 #define MODULES_VIDEO_CODING_CODECS_TEST_ENCODED_VIDEO_FRAME_PRODUCER_H_
13 
14 #include <stdint.h>
15 
16 #include <vector>
17 
18 #include "api/transport/rtp/dependency_descriptor.h"
19 #include "api/video/encoded_image.h"
20 #include "api/video_codecs/video_encoder.h"
21 #include "modules/video_coding/include/video_codec_interface.h"
22 
23 namespace webrtc {
24 
25 // Wrapper around VideoEncoder::Encode for convenient input (generates frames)
26 // and output (returns encoded frames instead of passing them to callback)
27 class EncodedVideoFrameProducer {
28  public:
29   struct EncodedFrame {
30     EncodedImage encoded_image;
31     CodecSpecificInfo codec_specific_info;
32   };
33 
34   // `encoder` should be initialized, but shouldn't have `EncoderCallback` set.
EncodedVideoFrameProducer(VideoEncoder & encoder)35   explicit EncodedVideoFrameProducer(VideoEncoder& encoder)
36       : encoder_(encoder) {}
37   EncodedVideoFrameProducer(const EncodedVideoFrameProducer&) = delete;
38   EncodedVideoFrameProducer& operator=(const EncodedVideoFrameProducer&) =
39       delete;
40 
41   // Number of the input frames to pass to the encoder.
42   EncodedVideoFrameProducer& SetNumInputFrames(int value);
43   // Resolution of the input frames.
44   EncodedVideoFrameProducer& SetResolution(RenderResolution value);
45 
46   EncodedVideoFrameProducer& SetFramerateFps(int value);
47 
48   // Generates input video frames and encodes them with `encoder` provided in
49   // the constructor. Returns frame passed to the `OnEncodedImage` by wraping
50   // `EncodedImageCallback` underneath.
51   std::vector<EncodedFrame> Encode();
52 
53  private:
54   VideoEncoder& encoder_;
55 
56   uint32_t rtp_timestamp_ = 1000;
57   int num_input_frames_ = 1;
58   int framerate_fps_ = 30;
59   RenderResolution resolution_ = {320, 180};
60 };
61 
SetNumInputFrames(int value)62 inline EncodedVideoFrameProducer& EncodedVideoFrameProducer::SetNumInputFrames(
63     int value) {
64   RTC_DCHECK_GT(value, 0);
65   num_input_frames_ = value;
66   return *this;
67 }
68 
SetResolution(RenderResolution value)69 inline EncodedVideoFrameProducer& EncodedVideoFrameProducer::SetResolution(
70     RenderResolution value) {
71   resolution_ = value;
72   return *this;
73 }
74 
SetFramerateFps(int value)75 inline EncodedVideoFrameProducer& EncodedVideoFrameProducer::SetFramerateFps(
76     int value) {
77   RTC_DCHECK_GT(value, 0);
78   framerate_fps_ = value;
79   return *this;
80 }
81 
82 }  // namespace webrtc
83 #endif  // MODULES_VIDEO_CODING_CODECS_TEST_ENCODED_VIDEO_FRAME_PRODUCER_H_
84