Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(507)

Side by Side Diff: content/renderer/media/rtc_video_encoder.h

Issue 20632002: Add media::VideoEncodeAccelerator with WebRTC integration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@git-svn
Patch Set: fcfd089c More comments addressed. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 content {
26
27 class RendererGpuVideoAcceleratorFactories;
28
29 // RTCVideoEncoder uses a media::VideoEncodeAccelerator to implement a
30 // webrtc::VideoEncoder class for WebRTC. Internally, VEA methods are
31 // trampolined to a private RTCVideoEncoder::Impl instance. The Impl class runs
32 // on the worker thread queried from the |gpu_factories_|, which is presently
33 // the media thread. RTCVideoEncoder itself is run and destroyed on the thread
34 // it is constructed on, which is presently the libjingle worker thread.
35 // Callbacks from the Impl due to its VEA::Client notifications are also posted
36 // back to RTCVideoEncoder on this thread.
37 class CONTENT_EXPORT RTCVideoEncoder
38 : NON_EXPORTED_BASE(public webrtc::VideoEncoder) {
39 public:
40 RTCVideoEncoder(
41 media::VideoCodecProfile profile,
42 const scoped_refptr<RendererGpuVideoAcceleratorFactories>& gpu_factories);
43 virtual ~RTCVideoEncoder();
44
45 // webrtc::VideoEncoder implementation. Tasks are posted to |impl_| using the
46 // appropriate VEA methods.
47 virtual int32_t InitEncode(const webrtc::VideoCodec* codec_settings,
48 int32_t number_of_cores,
49 uint32_t max_payload_size) OVERRIDE;
50 virtual int32_t Encode(
51 const webrtc::I420VideoFrame& input_image,
52 const webrtc::CodecSpecificInfo* codec_specific_info,
53 const std::vector<webrtc::VideoFrameType>* frame_types) OVERRIDE;
54 virtual int32_t RegisterEncodeCompleteCallback(
55 webrtc::EncodedImageCallback* callback) OVERRIDE;
56 virtual int32_t Release() OVERRIDE;
57 virtual int32_t SetChannelParameters(uint32_t packet_loss, int rtt) OVERRIDE;
58 virtual int32_t SetRates(uint32_t new_bit_rate,
59 uint32_t /* ignored_frame_rate*/) OVERRIDE;
60
61 private:
62 class Impl;
63 friend class RTCVideoEncoder::Impl;
64
65 // Return an encoded output buffer to WebRTC.
66 void ReturnEncodedImage(const scoped_refptr<Impl>& impl,
67 scoped_ptr<webrtc::EncodedImage> image,
68 int32 bitstream_buffer_id);
69
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<RendererGpuVideoAcceleratorFactories> gpu_factories_;
79
80 // Weak pointer and factory for posting back VEA::Client notifications to
81 // RTCVideoEncoder.
82 base::WeakPtrFactory<RTCVideoEncoder> weak_this_factory_;
83 base::WeakPtr<RTCVideoEncoder> weak_this_;
84
85 // webrtc::VideoEncoder encode complete callback.
86 webrtc::EncodedImageCallback* encoded_image_callback_;
87
88 // The RTCVideoEncoder::Impl that does all the work.
89 scoped_refptr<Impl> impl_;
90
91 // We cannot immediately return error conditions to the WebRTC user of this
92 // class, as there is no error callback in the webrtc::VideoEncoder interface.
93 // Instead, we cache an error status here and return it the next time an
94 // interface entry point is called.
95 int32_t impl_status_;
96
97 DISALLOW_COPY_AND_ASSIGN(RTCVideoEncoder);
98 };
99
100 } // namespace content
101
102 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_ENCODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698