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/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/threading/thread_checker.h" |
| 14 #include "content/common/content_export.h" |
| 15 #include "media/base/video_decoder_config.h" |
| 16 #include "third_party/webrtc/modules/video_coding/codecs/interface/video_codec_i
nterface.h" |
| 17 #include "ui/gfx/size.h" |
| 18 |
| 19 namespace base { |
| 20 |
| 21 class MessageLoopProxy; |
| 22 |
| 23 } // namespace base |
| 24 |
| 25 namespace media { |
| 26 |
| 27 class GpuVideoAcceleratorFactories; |
| 28 |
| 29 } // namespace media |
| 30 |
| 31 namespace content { |
| 32 |
| 33 // This class uses a media::VideoEncodeAccelerator to implement a |
| 34 // webrtc::VideoEncoder class for WebRTC. Internally, VEA methods are |
| 35 // trampolined to a private RTCVideoEncoder::Impl instance. The class runs on |
| 36 // the |impl_message_loop_proxy_|, which is queried from the |gpu_factories_| |
| 37 // and is presently the media thread. VEA::Client callbacks are posted back to |
| 38 // the thread that the RTCVideoEncoder constructor is called on. |
| 39 class CONTENT_EXPORT RTCVideoEncoder |
| 40 : NON_EXPORTED_BASE(public webrtc::VideoEncoder) { |
| 41 public: |
| 42 RTCVideoEncoder( |
| 43 media::VideoCodecProfile profile, |
| 44 const scoped_refptr<media::GpuVideoAcceleratorFactories>& gpu_factories); |
| 45 virtual ~RTCVideoEncoder(); |
| 46 |
| 47 // webrtc::VideoEncoder implementation. Tasks are posted to |impl_| using the |
| 48 // appropriate VEA methods. |
| 49 virtual int32_t InitEncode(const webrtc::VideoCodec* codec_settings, |
| 50 int32_t number_of_cores, |
| 51 uint32_t max_payload_size) OVERRIDE; |
| 52 virtual int32_t Encode( |
| 53 const webrtc::I420VideoFrame& input_image, |
| 54 const webrtc::CodecSpecificInfo* codec_specific_info, |
| 55 const std::vector<webrtc::VideoFrameType>* frame_types) OVERRIDE; |
| 56 virtual int32_t RegisterEncodeCompleteCallback( |
| 57 webrtc::EncodedImageCallback* callback) OVERRIDE; |
| 58 virtual int32_t Release() OVERRIDE; |
| 59 virtual int32_t SetChannelParameters(uint32_t packet_loss, int rtt) OVERRIDE; |
| 60 virtual int32_t SetRates(uint32_t new_bit_rate, uint32_t frame_rate) OVERRIDE; |
| 61 |
| 62 private: |
| 63 class Impl; |
| 64 friend class RTCVideoEncoder::Impl; |
| 65 |
| 66 // Return an encoded output buffer to WebRTC. |
| 67 void ReturnEncodedImage(const scoped_refptr<Impl>& impl, |
| 68 scoped_ptr<webrtc::EncodedImage> image, |
| 69 int32 bitstream_buffer_id); |
| 70 void NotifyError(const scoped_refptr<Impl>& impl, int32_t error); |
| 71 |
| 72 base::ThreadChecker thread_checker_; |
| 73 |
| 74 // The video codec profile we were created with. |
| 75 media::VideoCodecProfile video_codec_profile_; |
| 76 |
| 77 // Factory for creating VEAs, shared memory buffers, etc. |
| 78 scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories_; |
| 79 |
| 80 // Message loop that |impl_| runs on; queried from |gpu_factories_|. |
| 81 const scoped_refptr<base::MessageLoopProxy> impl_message_loop_proxy_; |
| 82 |
| 83 // Weak pointer and factory for posting back VEA::Client notifications to |
| 84 // RTCVideoEncoder. |
| 85 base::WeakPtrFactory<RTCVideoEncoder> weak_this_factory_; |
| 86 base::WeakPtr<RTCVideoEncoder> weak_this_; |
| 87 |
| 88 // webrtc::VideoEncoder encode complete callback. |
| 89 webrtc::EncodedImageCallback* encoded_image_callback_; |
| 90 |
| 91 // The RTCVideoEncoder::Impl that does all the work. |
| 92 scoped_refptr<Impl> impl_; |
| 93 |
| 94 // We cannot immediately return error conditions to the WebRTC user of this |
| 95 // class, as there is no error callback in the webrtc::VideoEncoder interface. |
| 96 // Instead, we cache an error status here and return it the next time an |
| 97 // interface entry point is called. |
| 98 int32_t impl_status_; |
| 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(RTCVideoEncoder); |
| 101 }; |
| 102 |
| 103 } // namespace content |
| 104 |
| 105 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_ENCODER_H_ |
OLD | NEW |