OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 * | 9 * |
10 */ | 10 */ |
11 | 11 |
12 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_ENCODER_ADAPTER_H_ | 12 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_ENCODER_ADAPTER_H_ |
13 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_ENCODER_ADAPTER_H_ | 13 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_ENCODER_ADAPTER_H_ |
14 | 14 |
| 15 #include <map> |
15 #include <memory> | 16 #include <memory> |
16 #include <string> | 17 #include <string> |
| 18 #include <utility> |
17 #include <vector> | 19 #include <vector> |
18 | 20 |
19 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" | 21 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" |
| 22 #include "webrtc/modules/video_coding/utility/simulcast_state.h" |
20 | 23 |
21 namespace webrtc { | 24 namespace webrtc { |
22 | 25 |
| 26 class SimulcastState; |
| 27 |
23 class VideoEncoderFactory { | 28 class VideoEncoderFactory { |
24 public: | 29 public: |
25 virtual VideoEncoder* Create() = 0; | 30 virtual VideoEncoder* Create() = 0; |
26 virtual void Destroy(VideoEncoder* encoder) = 0; | 31 virtual void Destroy(VideoEncoder* encoder) = 0; |
27 virtual ~VideoEncoderFactory() {} | 32 virtual ~VideoEncoderFactory() {} |
28 }; | 33 }; |
29 | 34 |
30 // SimulcastEncoderAdapter implements simulcast support by creating multiple | 35 // SimulcastEncoderAdapter implements simulcast support by creating multiple |
31 // webrtc::VideoEncoder instances with the given VideoEncoderFactory. | 36 // webrtc::VideoEncoder instances with the given VideoEncoderFactory. |
32 // All the public interfaces are expected to be called from the same thread, | 37 // All the public interfaces are expected to be called from the same thread, |
(...skipping 23 matching lines...) Expand all Loading... |
56 const CodecSpecificInfo* codecSpecificInfo = NULL, | 61 const CodecSpecificInfo* codecSpecificInfo = NULL, |
57 const RTPFragmentationHeader* fragmentation = NULL); | 62 const RTPFragmentationHeader* fragmentation = NULL); |
58 | 63 |
59 void OnDroppedFrame() override; | 64 void OnDroppedFrame() override; |
60 | 65 |
61 bool SupportsNativeHandle() const override; | 66 bool SupportsNativeHandle() const override; |
62 const char* ImplementationName() const override; | 67 const char* ImplementationName() const override; |
63 | 68 |
64 private: | 69 private: |
65 struct StreamInfo { | 70 struct StreamInfo { |
66 StreamInfo() | 71 StreamInfo() : encoder(nullptr), callback(nullptr), width(0), height(0) {} |
67 : encoder(NULL), | |
68 callback(NULL), | |
69 width(0), | |
70 height(0), | |
71 key_frame_request(false), | |
72 send_stream(true) {} | |
73 StreamInfo(VideoEncoder* encoder, | 72 StreamInfo(VideoEncoder* encoder, |
74 EncodedImageCallback* callback, | 73 EncodedImageCallback* callback, |
75 uint16_t width, | 74 uint16_t width, |
76 uint16_t height, | 75 uint16_t height) |
77 bool send_stream) | 76 : encoder(encoder), callback(callback), width(width), height(height) {} |
78 : encoder(encoder), | |
79 callback(callback), | |
80 width(width), | |
81 height(height), | |
82 key_frame_request(false), | |
83 send_stream(send_stream) {} | |
84 // Deleted by SimulcastEncoderAdapter::Release(). | 77 // Deleted by SimulcastEncoderAdapter::Release(). |
85 VideoEncoder* encoder; | 78 VideoEncoder* encoder; |
86 EncodedImageCallback* callback; | 79 EncodedImageCallback* callback; |
87 uint16_t width; | 80 uint16_t width; |
88 uint16_t height; | 81 uint16_t height; |
89 bool key_frame_request; | |
90 bool send_stream; | |
91 }; | 82 }; |
92 | 83 |
93 // Get the stream bitrate, for the stream |stream_idx|, given the bitrate | |
94 // |new_bitrate_kbit| and the actual configured stream count in | |
95 // |total_number_of_streams|. The function also returns whether there's enough | |
96 // bandwidth to send this stream via |send_stream|. | |
97 uint32_t GetStreamBitrate(int stream_idx, | |
98 size_t total_number_of_streams, | |
99 uint32_t new_bitrate_kbit, | |
100 bool* send_stream) const; | |
101 | |
102 // Populate the codec settings for each stream. | |
103 void PopulateStreamCodec(const webrtc::VideoCodec* inst, | |
104 int stream_index, | |
105 size_t total_number_of_streams, | |
106 bool highest_resolution_stream, | |
107 webrtc::VideoCodec* stream_codec, | |
108 bool* send_stream); | |
109 | |
110 bool Initialized() const; | 84 bool Initialized() const; |
111 | 85 |
112 std::unique_ptr<VideoEncoderFactory> factory_; | 86 std::unique_ptr<VideoEncoderFactory> factory_; |
113 std::unique_ptr<TemporalLayersFactory> screensharing_tl_factory_; | 87 std::unique_ptr<TemporalLayersFactory> screensharing_tl_factory_; |
114 VideoCodec codec_; | 88 VideoCodec codec_; |
115 std::vector<StreamInfo> streaminfos_; | 89 SimulcastState stream_states_; |
| 90 typedef std::pair<VideoEncoder*, std::unique_ptr<EncodedImageCallback>> |
| 91 EncoderContext; |
| 92 std::map<uint8_t, EncoderContext> encoders_; |
116 EncodedImageCallback* encoded_complete_callback_; | 93 EncodedImageCallback* encoded_complete_callback_; |
117 std::string implementation_name_; | 94 std::string implementation_name_; |
118 }; | 95 }; |
119 | 96 |
120 } // namespace webrtc | 97 } // namespace webrtc |
121 | 98 |
122 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_ENCODER_ADAPTER_H_ | 99 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_ENCODER_ADAPTER_H_ |
OLD | NEW |