OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_RENDERER_MEDIA_RTC_VIDEO_ENCODER_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_RTC_VIDEO_ENCODER_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/memory/scoped_vector.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/threading/thread_checker.h" |
| 13 #include "content/common/content_export.h" |
| 14 #include "media/base/video_decoder_config.h" |
| 15 #include "third_party/webrtc/modules/video_coding/codecs/interface/video_codec_i
nterface.h" |
| 16 #include "ui/gfx/size.h" |
| 17 |
| 18 namespace base { |
| 19 |
| 20 class MessageLoopProxy; |
| 21 |
| 22 } // namespace base |
| 23 |
| 24 namespace media { |
| 25 |
| 26 class GpuVideoAcceleratorFactories; |
| 27 |
| 28 } // namespace media |
| 29 |
| 30 namespace content { |
| 31 |
| 32 // This class uses a media::VideoEncodeAccelerator to implement a |
| 33 // webrtc::VideoEncoder class for WebRTC. Internally, VEA methods are |
| 34 // trampolined to a private RTCVideoEncoder::Impl instance. The class runs on |
| 35 // the |impl_message_loop_proxy_|, which is queried from the |gpu_factories_| |
| 36 // and is presently the media thread. VEA::Client callbacks are posted back to |
| 37 // the thread that the RTCVideoEncoder constructor is called on. |
| 38 class CONTENT_EXPORT RTCVideoEncoder |
| 39 : NON_EXPORTED_BASE(public webrtc::VideoEncoder) { |
| 40 public: |
| 41 RTCVideoEncoder( |
| 42 media::VideoCodecProfile profile, |
| 43 const scoped_refptr<media::GpuVideoAcceleratorFactories>& gpu_factories); |
| 44 virtual ~RTCVideoEncoder(); |
| 45 |
| 46 // webrtc::VideoEncoder implementation. Tasks are posted to |impl_| using the |
| 47 // appropriate VEA methods. |
| 48 virtual int32_t InitEncode(const webrtc::VideoCodec* codec_settings, |
| 49 int32_t number_of_cores, |
| 50 uint32_t max_payload_size) OVERRIDE; |
| 51 virtual int32_t Encode( |
| 52 const webrtc::I420VideoFrame& input_image, |
| 53 const webrtc::CodecSpecificInfo* codec_specific_info, |
| 54 const std::vector<webrtc::VideoFrameType>* frame_types) OVERRIDE; |
| 55 virtual int32_t RegisterEncodeCompleteCallback( |
| 56 webrtc::EncodedImageCallback* callback) OVERRIDE; |
| 57 virtual int32_t Release() OVERRIDE; |
| 58 virtual int32_t SetChannelParameters(uint32_t packet_loss, int rtt) OVERRIDE; |
| 59 virtual int32_t SetRates(uint32_t new_bit_rate, uint32_t frame_rate) OVERRIDE; |
| 60 |
| 61 private: |
| 62 class Impl; |
| 63 friend class RTCVideoEncoder::Impl; |
| 64 |
| 65 enum { |
| 66 kInputBufferExtraCount = 1, // The number of input buffers allocated, more |
| 67 // than what is requested by |
| 68 // VEA::RequireBitstreamBuffers(). |
| 69 kOutputBufferCount = 3, |
| 70 }; |
| 71 |
| 72 // Handlers for VEA::Client methods, which translate back to the |
| 73 // WebRTC::VideoEncoder methods. |
| 74 void RequireBitstreamBuffers(int input_count, |
| 75 const gfx::Size& input_dimensions, |
| 76 size_t output_size); |
| 77 void NotifyInputDone(int32 bitstream_buffer_id); |
| 78 void BitstreamBufferReady(int32 bitstream_buffer_id, |
| 79 size_t size, |
| 80 bool key_frame); |
| 81 void NotifyError(int32_t error); |
| 82 |
| 83 base::ThreadChecker thread_checker_; |
| 84 |
| 85 // The video codec profile we were created with. |
| 86 media::VideoCodecProfile video_codec_profile_; |
| 87 |
| 88 // Factory for creating VEAs, shared memory buffers, etc. |
| 89 const scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories_; |
| 90 |
| 91 // Message loop that |impl_| runs on; queried from |gpu_factories_|. |
| 92 const scoped_refptr<base::MessageLoopProxy> impl_message_loop_proxy_; |
| 93 |
| 94 // Weak pointer and factory for posting back VEA::Client notifications to |
| 95 // RTCVideoEncoder. |
| 96 base::WeakPtrFactory<RTCVideoEncoder> weak_this_factory_; |
| 97 base::WeakPtr<RTCVideoEncoder> weak_this_; |
| 98 |
| 99 // webrtc::VideoEncoder encode complete callback. |
| 100 webrtc::EncodedImageCallback* encoded_image_callback_; |
| 101 |
| 102 // The RTCVideoEncoder::Impl that does all the work. |
| 103 scoped_ptr<Impl> impl_; |
| 104 |
| 105 // We cannot immediately return error conditions to the WebRTC user of this |
| 106 // class, as there is no error callback in the webrtc::VideoEncoder interface. |
| 107 // Instead, we cache an error status here and return it the next time an |
| 108 // interface entry point is called. |
| 109 int32_t impl_status_; |
| 110 |
| 111 // Frame parameters. |
| 112 gfx::Size input_frame_dimensions_; |
| 113 gfx::Size output_frame_dimensions_; |
| 114 |
| 115 // Required output buffer size. |
| 116 size_t output_buffer_size_; |
| 117 |
| 118 // Shared memory buffers for input/output with the VEA. |
| 119 ScopedVector<base::SharedMemory> input_buffers_; |
| 120 ScopedVector<base::SharedMemory> output_buffers_; |
| 121 |
| 122 // Input buffers ready to be filled with input from Encode(). |
| 123 std::vector<int> input_buffers_free_; |
| 124 |
| 125 DISALLOW_COPY_AND_ASSIGN(RTCVideoEncoder); |
| 126 }; |
| 127 |
| 128 } // namespace content |
| 129 |
| 130 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_ENCODER_H_ |
OLD | NEW |