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

Side by Side Diff: content/renderer/media/rtc_video_decoder_bridge_tv.cc

Issue 14247018: Implement WebRTC in Chrome for TV (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Dongwon and Yuncheol's comments Created 7 years, 7 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 (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_video_decoder_bridge_tv.h"
6
7 #include <queue>
8
9 #include "base/bind.h"
10 #include "base/callback_helpers.h"
11 #include "base/location.h"
12 #include "base/logging.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/singleton.h"
15 #include "base/message_loop_proxy.h"
16 #include "base/time.h"
17 #include "content/renderer/media/rtc_video_decoder_factory_tv.h"
18 #include "media/base/bind_to_loop.h"
19 #include "media/base/decoder_buffer.h"
20 #include "third_party/libjingle/source/talk/base/ratetracker.h"
21
22 namespace content {
23
24 RTCVideoDecoderBridgeTv::RTCVideoDecoderBridgeTv(
25 RTCVideoDecoderFactoryTv* factory)
26 : factory_(factory),
27 is_initialized_(false),
28 first_frame_(true),
29 decode_complete_callback_(NULL) {}
30
31 RTCVideoDecoderBridgeTv::~RTCVideoDecoderBridgeTv() {}
32
33 int32_t RTCVideoDecoderBridgeTv::InitDecode(
34 const webrtc::VideoCodec* codecSettings,
acolwell GONE FROM CHROMIUM 2013/05/14 18:17:47 nit: change to unix_hacker_style here and below.
wonsik 2013/05/20 14:02:24 Done.
35 int32_t numberOfCores) {
36 if (codecSettings->codecType != webrtc::kVideoCodecVP8)
37 return WEBRTC_VIDEO_CODEC_ERROR;
38 // We don't support feedback mode.
39 if (codecSettings->codecSpecific.VP8.feedbackModeOn)
40 return WEBRTC_VIDEO_CODEC_ERROR;
41
42 if (is_initialized_)
acolwell GONE FROM CHROMIUM 2013/05/14 18:17:47 nit: collapse this and the 2 conditions above into
wonsik 2013/05/20 14:02:24 Done.
43 return WEBRTC_VIDEO_CODEC_ERROR;
44 size_ = gfx::Size(codecSettings->width, codecSettings->height);
45 is_initialized_ = true;
46 first_frame_ = true;
47 factory_->InitializeStream(size_);
48
49 return WEBRTC_VIDEO_CODEC_OK;
50 }
51
52 int32_t RTCVideoDecoderBridgeTv::Decode(
53 const webrtc::EncodedImage& inputImage,
54 bool missingFrames,
55 const webrtc::RTPFragmentationHeader* /* fragmentation */,
acolwell GONE FROM CHROMIUM 2013/05/14 18:17:47 are these commented out to silence a warning? If n
wonsik 2013/05/20 14:02:24 Done.
56 const webrtc::CodecSpecificInfo* /* codecSpecificInfo */,
57 int64_t renderTimeMs) {
58 // Unlike the SW decoder in libvpx, hw decoder can not handle broken frames.
59 // Here, we return an error in order to request a key frame.
60 if (missingFrames || !inputImage._completeFrame)
61 return WEBRTC_VIDEO_CODEC_ERROR;
62
63 if (!is_initialized_ || decode_complete_callback_ == NULL)
64 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
65
66 if (first_frame_) {
67 // If the first frame is not a key frame, return an error to request a key
68 // frame.
69 if (inputImage._frameType != webrtc::kKeyFrame)
70 return WEBRTC_VIDEO_CODEC_ERROR;
71
72 // Google TV expects timestamp from 0, so we store the initial timestamp as
73 // an offset and subtract the value from every timestamps to meet the
74 // expectation.
75 timestamp_offset_millis_ = renderTimeMs;
76 }
77 first_frame_ = false;
78 gfx::Size new_size;
79 if (inputImage._frameType == webrtc::kKeyFrame &&
80 inputImage._encodedWidth != 0 &&
81 inputImage._encodedHeight != 0) {
82 // Only a key frame has a meaningful size.
83 new_size.SetSize(inputImage._encodedWidth, inputImage._encodedHeight);
84 if (size_ == new_size)
85 new_size = gfx::Size();
86 else
87 size_ = new_size;
88 }
89 // |inputImage_| may be destroyed after this call, so we make a copy of the
90 // buffer so that we can queue the buffer asynchronously.
91 scoped_refptr<media::DecoderBuffer> buffer =
92 media::DecoderBuffer::CopyFrom(inputImage._buffer, inputImage._length);
93 if (renderTimeMs != -1) {
94 buffer->SetTimestamp(base::TimeDelta::FromMilliseconds(
95 renderTimeMs - timestamp_offset_millis_));
96 }
97
98 factory_->QueueBuffer(
99 buffer,
100 base::Bind(&RTCVideoDecoderBridgeTv::RunDecodeCompleteCallback,
101 decode_complete_callback_,
102 inputImage._timeStamp),
103 new_size);
104
105 return WEBRTC_VIDEO_CODEC_OK;
106 }
107
108 int32_t RTCVideoDecoderBridgeTv::RegisterDecodeCompleteCallback(
109 webrtc::DecodedImageCallback* callback) {
110 decode_complete_callback_ = callback;
111 return WEBRTC_VIDEO_CODEC_OK;
112 }
113
114 int32_t RTCVideoDecoderBridgeTv::Release() {
115 is_initialized_ = false;
116 return WEBRTC_VIDEO_CODEC_OK;
117 }
118
119 int32_t RTCVideoDecoderBridgeTv::Reset() {
120 first_frame_ = true;
121 return WEBRTC_VIDEO_CODEC_OK;
122 }
123
124 // static
125 void RTCVideoDecoderBridgeTv::RunDecodeCompleteCallback(
126 webrtc::DecodedImageCallback* callback,
127 int64_t timestamp) {
128 // We call the decode complete callback function to notify libjingle that
129 // decoding is finished. In addition, this also reports back to libjingle that
130 // the particular video frame with |timestamp| is correctly rendered to
131 // libjingle, so that it can generate proper stats.
132 webrtc::I420VideoFrame dummy_video_frame;
133 // Smallest possible non-zero I420 image is 2x2 square, with stride_y being 2
134 // and stride_u & stride_v being 1. In other words, this dummy frame contains
135 // 2x2 y values and 1x1 u & v values each.
136 dummy_video_frame.CreateEmptyFrame(2, 2, 2, 1, 1);
acolwell GONE FROM CHROMIUM 2013/05/14 18:17:47 doesn't libjingle care about the frame size too? S
wonsik 2013/05/20 14:02:24 AFAIK libjingle does not report the size of image
palmer 2013/05/20 15:35:17 How does not passing the size save much space or t
acolwell GONE FROM CHROMIUM 2013/05/20 21:23:21 Is there a way we can reuse a frame so we only hav
wonsik 2013/05/21 10:09:29 OK - not lying now :)
137 dummy_video_frame.set_timestamp(timestamp);
138 callback->Decoded(dummy_video_frame);
139 }
140
141 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698