Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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 #include "content/renderer/media/rtc_encoding_video_capturer.h" | |
| 6 | |
| 7 #include "media/base/encoded_bitstream_buffer.h" | |
| 8 | |
| 9 namespace content { | |
| 10 | |
| 11 // Wrapper to for EncodedVideoBitstream that retains known state information | |
| 12 // for incoming bitstream. | |
| 13 class RtcEncodingVideoCapturer::Bitstream : | |
| 14 public media::EncodedVideoBitstream::Client, | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
This implies the name of the class is poor - it's
hshi1
2013/06/10 21:49:35
How about "BitstreamClient"? See updated CL.
| |
| 15 public base::RefCountedThreadSafe<RtcEncodingVideoCapturer::Bitstream> { | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
why refcount?
hshi1
2013/06/10 21:49:35
Refcount is not really needed, I just need it to b
| |
| 16 public: | |
| 17 Bitstream(media::VideoEncodingParameters params, | |
| 18 media::EncodedVideoSource* encoded_video_source); | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
doco lifetime
| |
| 19 | |
| 20 // Function to configure runtime encoding parameters. | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
Isn't this really just the EVB interface?
hshi1
2013/06/10 21:49:35
... yes, what was I thinking. This is completely b
| |
| 21 void Configure(const media::RuntimeVideoEncodingParameters& params); | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
Try?
hshi1
2013/06/10 21:49:35
This is no longer needed.
| |
| 22 | |
| 23 // media::EncodedVideoBitstream::Client implementation. | |
| 24 virtual void OnBitstreamStreaming( | |
| 25 scoped_refptr<media::EncodedVideoBitstream> bitstream, | |
| 26 const media::VideoEncodingParameters& params) OVERRIDE; | |
| 27 virtual void OnBitstreamRemoved( | |
| 28 scoped_refptr<media::EncodedVideoBitstream> bitstream) OVERRIDE; | |
| 29 virtual void OnBitstreamReady( | |
| 30 scoped_refptr<media::EncodedVideoBitstream> bitstream, | |
| 31 scoped_refptr<const media::EncodedBitstreamBuffer> buffer) OVERRIDE; | |
| 32 virtual void OnBitstreamConfigChanged( | |
| 33 scoped_refptr<media::EncodedVideoBitstream> bitstream, | |
| 34 const media::RuntimeVideoEncodingParameters& params) OVERRIDE; | |
| 35 | |
| 36 // Getters and setters for bitstream properties. | |
| 37 bool finished() const; | |
| 38 media::RuntimeVideoEncodingParameters runtime_params() const; | |
| 39 void set_round_trip_time(int rtt_in_ms); | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
use TimeDelta for the param
hshi1
2013/06/10 19:12:31
Done.
| |
| 40 void set_callback(webrtc::EncodedImageCallback* callback); | |
| 41 | |
| 42 private: | |
| 43 virtual ~Bitstream(); | |
| 44 friend class base::RefCountedThreadSafe<RtcEncodingVideoCapturer::Bitstream>; | |
| 45 | |
| 46 // Helper to convert buffer to webrtc types in callback. | |
| 47 bool Convert(scoped_refptr<const media::EncodedBitstreamBuffer> buffer, | |
| 48 webrtc::EncodedImage& image, | |
| 49 webrtc::CodecSpecificInfo& codecInfo, | |
| 50 webrtc::RTPFragmentationHeader& fragHeader); | |
| 51 | |
| 52 media::VideoEncodingParameters params_; | |
| 53 bool finished_; | |
| 54 | |
| 55 // Representing incoming stream. | |
| 56 scoped_refptr<media::EncodedVideoBitstream> bitstream_; | |
| 57 | |
| 58 base::Time time_base_; | |
| 59 base::TimeDelta round_trip_time_; | |
| 60 media::EncodedVideoSource* encoded_video_source_; | |
| 61 webrtc::EncodedImageCallback* callback_; | |
| 62 DISALLOW_COPY_AND_ASSIGN(Bitstream); | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
nit: extra \n before this
hshi1
2013/06/10 19:12:31
Done.
| |
| 63 }; | |
| 64 | |
| 65 RtcEncodingVideoCapturer::Bitstream::Bitstream( | |
| 66 media::VideoEncodingParameters params, | |
| 67 media::EncodedVideoSource* encoded_video_source) | |
| 68 : params_(params), | |
| 69 finished_(false), | |
| 70 encoded_video_source_(encoded_video_source) { | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
initialize all other members to known-reasonable s
hshi1
2013/06/10 21:49:35
Done.
| |
| 71 if (encoded_video_source_) | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
how can this fail?
hshi1
2013/06/10 21:49:35
Done.
| |
| 72 bitstream_ = encoded_video_source_->OpenBitstream(this, params); | |
| 73 } | |
| 74 | |
| 75 RtcEncodingVideoCapturer::Bitstream::~Bitstream() { | |
| 76 if (encoded_video_source_ && bitstream_) { | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
how can this fail?
hshi1
2013/06/10 21:49:35
Well encoded_video_source_ should be valid, but bi
| |
| 77 encoded_video_source_->CloseBitstream(bitstream_); | |
| 78 bitstream_ = NULL; | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
why bother?
hshi1
2013/06/10 21:49:35
Done.
| |
| 79 } | |
| 80 } | |
| 81 | |
| 82 void RtcEncodingVideoCapturer::Bitstream::Configure( | |
| 83 const media::RuntimeVideoEncodingParameters& params) { | |
| 84 if (bitstream_) | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
how can this fail?
hshi1
2013/06/10 21:49:35
Can fail if OpenBitstream failed, or bitstream is
| |
| 85 bitstream_->TryConfigure(params); | |
| 86 } | |
| 87 | |
| 88 bool RtcEncodingVideoCapturer::Bitstream::finished() const { | |
| 89 return finished_; | |
| 90 } | |
| 91 | |
| 92 media::RuntimeVideoEncodingParameters | |
| 93 RtcEncodingVideoCapturer::Bitstream::runtime_params() const { | |
| 94 return params_.runtime_params; | |
| 95 } | |
| 96 | |
| 97 void RtcEncodingVideoCapturer::Bitstream::set_round_trip_time(int rtt_in_ms) { | |
| 98 round_trip_time_ = base::TimeDelta::FromMilliseconds(rtt_in_ms); | |
| 99 } | |
| 100 | |
| 101 void RtcEncodingVideoCapturer::Bitstream::set_callback( | |
| 102 webrtc::EncodedImageCallback* callback) { | |
| 103 callback_ = callback; | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
DCHECK(!callback_);
first?
hshi1
2013/06/10 21:49:35
Done.
| |
| 104 } | |
| 105 | |
| 106 void RtcEncodingVideoCapturer::Bitstream::OnBitstreamStreaming( | |
| 107 scoped_refptr<media::EncodedVideoBitstream> bitstream, | |
| 108 const media::VideoEncodingParameters& params) { | |
| 109 params_ = params; | |
| 110 } | |
| 111 | |
| 112 void RtcEncodingVideoCapturer::Bitstream::OnBitstreamRemoved( | |
| 113 scoped_refptr<media::EncodedVideoBitstream> bitstream) { | |
| 114 finished_ = true; | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
bitstream_ = NULL;
?
hshi1
2013/06/10 21:49:35
Done.
| |
| 115 } | |
| 116 | |
| 117 void RtcEncodingVideoCapturer::Bitstream::OnBitstreamReady( | |
| 118 scoped_refptr<media::EncodedVideoBitstream> bitstream, | |
| 119 scoped_refptr<const media::EncodedBitstreamBuffer> buffer) { | |
| 120 if (callback_) { | |
| 121 // First buffer constitutes the origin of the time for this bitstream | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
Isn't this true regardless of callback_ being set?
hshi1
2013/06/10 21:49:35
Yes but if callback_ is not set then we can't call
| |
| 122 // context. | |
| 123 if (time_base_.is_null()) { | |
| 124 time_base_ = buffer->metadata().timestamp; | |
| 125 } | |
| 126 // Convert EncodedBitstreamBuffer to webrtc types. | |
| 127 webrtc::EncodedImage image; | |
| 128 webrtc::CodecSpecificInfo codecInfo; | |
| 129 webrtc::RTPFragmentationHeader fragInfo; | |
| 130 if (Convert(buffer, image, codecInfo, fragInfo)) { | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
style: no non-const ref params. These are output
hshi1
2013/06/10 21:49:35
Done.
| |
| 131 callback_->Encoded(image, &codecInfo, &fragInfo); | |
| 132 } | |
| 133 } | |
| 134 // Return buffer so it can be reused for encoding upcoming bitstream. | |
| 135 if (encoded_video_source_) | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
can never be false.
hshi1
2013/06/10 21:49:35
Done.
| |
| 136 encoded_video_source_->ReturnBitstreamBuffer(bitstream, buffer); | |
| 137 } | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
This collection of comments reduces l.120-136 into
hshi1
2013/06/10 21:49:35
Done.
| |
| 138 | |
| 139 void RtcEncodingVideoCapturer::Bitstream::OnBitstreamConfigChanged( | |
| 140 scoped_refptr<media::EncodedVideoBitstream> bitstream, | |
| 141 const media::RuntimeVideoEncodingParameters& params) { | |
| 142 params_.runtime_params = params; | |
| 143 } | |
| 144 | |
| 145 bool RtcEncodingVideoCapturer::Bitstream::Convert( | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
return value is ignored at only callsite and no le
hshi1
2013/06/10 21:49:35
Made it void.
| |
| 146 scoped_refptr<const media::EncodedBitstreamBuffer> buffer, | |
| 147 webrtc::EncodedImage& image, | |
| 148 webrtc::CodecSpecificInfo& codecInfo, | |
| 149 webrtc::RTPFragmentationHeader& fragHeader) { | |
| 150 DCHECK(buffer); | |
| 151 if (!buffer) { | |
| 152 return false; | |
| 153 } | |
| 154 | |
| 155 // TODO: remove this const_cast. Unfortunately webrtc::EncodedImage defines | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
TODO's should always be attributed like TODO(hshi)
hshi1
2013/06/10 21:49:35
Done.
| |
| 156 // member |_buffer| of type uint8_t* even though webrtc never modifies the | |
| 157 // buffer contents. | |
| 158 image._buffer = const_cast<uint8_t*>(buffer->buffer()); | |
| 159 image._length = buffer->size(); | |
| 160 image._size = image._length; | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
Do you know what the diff is supposed to be betwee
hshi1
2013/06/10 21:49:35
|_size| is supposed to indicate buffer capacity, a
| |
| 161 | |
| 162 const media::BufferEncodingMetadata& metadata = buffer->metadata(); | |
| 163 image.capture_time_ms_ = | |
| 164 (metadata.timestamp - time_base_).InMilliseconds(); // 1 KHz | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
Comment doesn't make sense to me.
hshi1
2013/06/10 21:49:35
Done.
| |
| 165 image._timeStamp = image.capture_time_ms_ * 90; // 90kHz | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
Once we finalize this CL IWBN to have mflodman@ or
hshi1
2013/06/10 21:49:35
I agree that this is not accurate; please review t
| |
| 166 if (metadata.key_frame) { | |
| 167 image._frameType = webrtc::kKeyFrame; | |
| 168 } else { | |
| 169 image._frameType = webrtc::kDeltaFrame; | |
| 170 } | |
| 171 image._completeFrame = true; | |
| 172 image._encodedWidth = params_.resolution.width(); | |
| 173 image._encodedHeight = params_.resolution.height(); | |
| 174 | |
| 175 // TODO: generate codec specific info for VP8. | |
| 176 codecInfo.codecType = webrtc::kVideoCodecGeneric; | |
| 177 | |
| 178 // Generate header containing a single fragmentation. | |
| 179 fragHeader.VerifyAndAllocateFragmentationHeader(1); | |
| 180 fragHeader.fragmentationOffset[0] = 0; | |
| 181 fragHeader.fragmentationLength[0] = buffer->size(); | |
| 182 fragHeader.fragmentationPlType[0] = 0; | |
| 183 fragHeader.fragmentationTimeDiff[0] = 0; | |
| 184 | |
| 185 return true; | |
| 186 } | |
| 187 | |
| 188 // RtcEncodingVideoCapturer | |
| 189 RtcEncodingVideoCapturer::RtcEncodingVideoCapturer( | |
| 190 int stream_id, | |
| 191 media::EncodedVideoSource* encoded_video_source) | |
| 192 : stream_id_(stream_id), | |
| 193 encoded_video_source_(encoded_video_source) { | |
| 194 } | |
| 195 | |
| 196 RtcEncodingVideoCapturer::~RtcEncodingVideoCapturer() { | |
| 197 } | |
| 198 | |
| 199 int32_t RtcEncodingVideoCapturer::InitEncode( | |
| 200 const webrtc::VideoCodec* codecSettings, | |
| 201 int32_t numberOfCores, | |
| 202 uint32_t maxPayloadSize) { | |
| 203 DCHECK(!bitstream_); | |
| 204 if (!bitstream_) { | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
How can this fail?
(and if you wanted to handle In
hshi1
2013/06/10 21:49:35
Done.
| |
| 205 // Convert |codecSettings| to |params|. | |
| 206 media::VideoEncodingParameters params; | |
| 207 params.codec_name = codecSettings->plName; | |
| 208 params.resolution = gfx::Size(codecSettings->width, codecSettings->height); | |
| 209 params.frames_per_second = codecSettings->maxFramerate; | |
| 210 params.runtime_params.average_bitrate = codecSettings->maxBitrate; | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
s/max/start/ ?
hshi1
2013/06/10 19:12:31
Done.
| |
| 211 params.runtime_params.max_bitrate = codecSettings->maxBitrate; | |
| 212 bitstream_ = new Bitstream(params, encoded_video_source_); | |
| 213 } | |
| 214 return WEBRTC_VIDEO_CODEC_OK; | |
| 215 } | |
| 216 | |
| 217 int32_t RtcEncodingVideoCapturer::Encode( | |
| 218 const webrtc::I420VideoFrame& inputImage, | |
| 219 const webrtc::CodecSpecificInfo* codecSpecificInfo, | |
| 220 const std::vector<webrtc::VideoFrameType>* frame_types) { | |
| 221 // TODO: request specific frame type. | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
TODO(hshi)
hshi1
2013/06/10 19:12:31
Done.
| |
| 222 return WEBRTC_VIDEO_CODEC_OK; | |
| 223 } | |
| 224 | |
| 225 int32_t RtcEncodingVideoCapturer::RegisterEncodeCompleteCallback( | |
| 226 webrtc::EncodedImageCallback* callback) { | |
| 227 if (!bitstream_) | |
| 228 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; | |
| 229 bitstream_->set_callback(callback); | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
Are you really not guaranteed that RECC is called
hshi1
2013/06/10 21:49:35
You're right.
| |
| 230 return WEBRTC_VIDEO_CODEC_OK; | |
| 231 } | |
| 232 | |
| 233 int32_t RtcEncodingVideoCapturer::Release() { | |
| 234 DCHECK(bitstream_); | |
| 235 bitstream_ = NULL; | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
Are you relying on this moving the refcount to 0?
| |
| 236 return WEBRTC_VIDEO_CODEC_OK; | |
| 237 } | |
| 238 | |
| 239 int32_t RtcEncodingVideoCapturer::SetChannelParameters( | |
| 240 uint32_t packetLoss, | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
/* packetLoss */ here & in the header
hshi1
2013/06/10 19:12:31
Done.
| |
| 241 int rtt_in_ms) { | |
| 242 if (!bitstream_) | |
| 243 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; | |
| 244 bitstream_->set_round_trip_time(rtt_in_ms); | |
| 245 return WEBRTC_VIDEO_CODEC_OK; | |
| 246 } | |
| 247 | |
| 248 int32_t RtcEncodingVideoCapturer::SetRates(uint32_t newBitRate, | |
| 249 uint32_t frameRate) { | |
| 250 if (!bitstream_) | |
| 251 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; | |
| 252 // TODO: wire up runtime rate control. | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
TODO(hshi)
hshi1
2013/06/10 19:12:31
Done.
| |
| 253 return WEBRTC_VIDEO_CODEC_OK; | |
| 254 } | |
| 255 | |
| 256 } // namespace content | |
| OLD | NEW |