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

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: fix bugs 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* codec_settings,
35 int32_t number_of_cores) {
36 // We don't support non-VP8 codec, feedback mode, nor double-initialization
37 if (codec_settings->codecType != webrtc::kVideoCodecVP8 ||
38 codec_settings->codecSpecific.VP8.feedbackModeOn || is_initialized_)
39 return WEBRTC_VIDEO_CODEC_ERROR;
40 size_ = gfx::Size(codec_settings->width, codec_settings->height);
41
42 is_initialized_ = true;
43 first_frame_ = true;
44 factory_->InitializeStream(size_);
45
46 return WEBRTC_VIDEO_CODEC_OK;
47 }
48
49 int32_t RTCVideoDecoderBridgeTv::Decode(
50 const webrtc::EncodedImage& input_image,
51 bool missing_frames,
52 const webrtc::RTPFragmentationHeader* fragmentation,
53 const webrtc::CodecSpecificInfo* codec_specific_info,
54 int64_t render_time_ms) {
55 // Unlike the SW decoder in libvpx, hw decoder can not handle broken frames.
56 // Here, we return an error in order to request a key frame.
57 if (missing_frames || !input_image._completeFrame)
58 return WEBRTC_VIDEO_CODEC_ERROR;
59
60 if (!is_initialized_ || decode_complete_callback_ == NULL)
61 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
62
63 if (first_frame_) {
64 // If the first frame is not a key frame, return an error to request a key
65 // frame.
66 if (input_image._frameType != webrtc::kKeyFrame)
67 return WEBRTC_VIDEO_CODEC_ERROR;
68
69 // Google TV expects timestamp from 0, so we store the initial timestamp as
70 // an offset and subtract the value from every timestamps to meet the
71 // expectation.
72 timestamp_offset_millis_ = render_time_ms;
73 }
74 first_frame_ = false;
75 gfx::Size new_size;
76 if (input_image._frameType == webrtc::kKeyFrame &&
77 input_image._encodedWidth != 0 && input_image._encodedHeight != 0) {
78 // Only a key frame has a meaningful size.
79 new_size.SetSize(input_image._encodedWidth, input_image._encodedHeight);
80 if (size_ == new_size)
81 new_size = gfx::Size();
82 else
83 size_ = new_size;
84 }
85 // |input_image_| may be destroyed after this call, so we make a copy of the
86 // buffer so that we can queue the buffer asynchronously.
87 scoped_refptr<media::DecoderBuffer> buffer =
88 media::DecoderBuffer::CopyFrom(input_image._buffer, input_image._length);
89 if (render_time_ms != -1) {
acolwell GONE FROM CHROMIUM 2013/05/20 21:23:22 What is supposed to happen when render_time_ms ==
wonsik 2013/05/21 10:09:29 Timestamp serves as a cue only, so I think it's fi
90 buffer->SetTimestamp(base::TimeDelta::FromMilliseconds(
91 render_time_ms - timestamp_offset_millis_));
92 }
93
94 factory_->QueueBuffer(
95 buffer,
96 base::Bind(&RTCVideoDecoderBridgeTv::RunDecodeCompleteCallback,
97 decode_complete_callback_,
98 input_image._timeStamp),
99 new_size);
100
101 return WEBRTC_VIDEO_CODEC_OK;
102 }
103
104 int32_t RTCVideoDecoderBridgeTv::RegisterDecodeCompleteCallback(
105 webrtc::DecodedImageCallback* callback) {
106 decode_complete_callback_ = callback;
107 return WEBRTC_VIDEO_CODEC_OK;
108 }
109
110 int32_t RTCVideoDecoderBridgeTv::Release() {
111 is_initialized_ = false;
112 return WEBRTC_VIDEO_CODEC_OK;
113 }
114
115 int32_t RTCVideoDecoderBridgeTv::Reset() {
116 first_frame_ = true;
117 return WEBRTC_VIDEO_CODEC_OK;
118 }
119
120 // static
121 void RTCVideoDecoderBridgeTv::RunDecodeCompleteCallback(
122 webrtc::DecodedImageCallback* callback,
123 int64_t timestamp) {
124 // We call the decode complete callback function to notify libjingle that
125 // decoding is finished. In addition, this also reports back to libjingle that
126 // the particular video frame with |timestamp| is correctly rendered to
127 // libjingle, so that it can generate proper stats.
128 webrtc::I420VideoFrame dummy_video_frame;
129 // Smallest possible non-zero I420 image is 2x2 square, with stride_y being 2
130 // and stride_u & stride_v being 1. In other words, this dummy frame contains
131 // 2x2 y values and 1x1 u & v values each.
132 dummy_video_frame.CreateEmptyFrame(2, 2, 2, 1, 1);
133 dummy_video_frame.set_timestamp(timestamp);
134 callback->Decoded(dummy_video_frame);
135 }
136
137 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698