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_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) { | |
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 size_), | |
100 new_size); | |
101 | |
102 return WEBRTC_VIDEO_CODEC_OK; | |
103 } | |
104 | |
105 int32_t RTCVideoDecoderBridgeTv::RegisterDecodeCompleteCallback( | |
106 webrtc::DecodedImageCallback* callback) { | |
107 decode_complete_callback_ = callback; | |
108 return WEBRTC_VIDEO_CODEC_OK; | |
109 } | |
110 | |
111 int32_t RTCVideoDecoderBridgeTv::Release() { | |
112 is_initialized_ = false; | |
113 return WEBRTC_VIDEO_CODEC_OK; | |
114 } | |
115 | |
116 int32_t RTCVideoDecoderBridgeTv::Reset() { | |
117 first_frame_ = true; | |
118 return WEBRTC_VIDEO_CODEC_OK; | |
119 } | |
120 | |
121 // static | |
122 void RTCVideoDecoderBridgeTv::RunDecodeCompleteCallback( | |
123 webrtc::DecodedImageCallback* callback, | |
124 int64_t timestamp, | |
125 gfx::Size size) { | |
126 // We call the decode complete callback function to notify libjingle that | |
127 // decoding is finished. In addition, this also reports back to libjingle that | |
128 // the particular video frame with |timestamp| is correctly rendered to | |
129 // libjingle, so that it can generate proper stats. | |
130 webrtc::I420VideoFrame dummy_video_frame; | |
131 // Smallest possible non-zero I420 image is 2x2 square, with stride_y being 2 | |
132 // and stride_u & stride_v being 1. In other words, this dummy frame contains | |
133 // 2x2 y values and 1x1 u & v values each. | |
acolwell GONE FROM CHROMIUM
2013/05/21 15:51:47
nit: remove comment since it doesn't apply anymore
wonsik
2013/05/22 07:56:10
Done.
| |
134 int half_width = (size.width() + 1) / 2; | |
135 dummy_video_frame.CreateEmptyFrame( | |
136 size.width(), size.height(), size.width(), half_width, half_width); | |
137 dummy_video_frame.set_timestamp(timestamp); | |
138 callback->Decoded(dummy_video_frame); | |
139 } | |
140 | |
141 } // namespace content | |
OLD | NEW |