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

Side by Side Diff: remoting/base/decoder_vp8.cc

Issue 4476003: Add VideoPacket struct for video packets. Refactor Decode interface to use it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged Created 10 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « remoting/base/decoder_vp8.h ('k') | remoting/base/encoder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/base/decoder_vp8.h" 5 #include "remoting/base/decoder_vp8.h"
6 6
7 #include "media/base/media.h" 7 #include "media/base/media.h"
8 #include "media/base/yuv_convert.h" 8 #include "media/base/yuv_convert.h"
9 #include "remoting/base/util.h" 9 #include "remoting/base/util.h"
10 10
(...skipping 12 matching lines...) Expand all
23 } 23 }
24 24
25 DecoderVp8::~DecoderVp8() { 25 DecoderVp8::~DecoderVp8() {
26 if (codec_) { 26 if (codec_) {
27 vpx_codec_err_t ret = vpx_codec_destroy(codec_); 27 vpx_codec_err_t ret = vpx_codec_destroy(codec_);
28 CHECK(ret == VPX_CODEC_OK) << "Failed to destroy codec"; 28 CHECK(ret == VPX_CODEC_OK) << "Failed to destroy codec";
29 } 29 }
30 delete codec_; 30 delete codec_;
31 } 31 }
32 32
33 void DecoderVp8::Initialize(scoped_refptr<media::VideoFrame> frame, 33 void DecoderVp8::Initialize(scoped_refptr<media::VideoFrame> frame) {
34 const gfx::Rect& clip, int bytes_per_src_pixel) {
35 DCHECK_EQ(kUninitialized, state_); 34 DCHECK_EQ(kUninitialized, state_);
36 35
37 if (frame->format() != media::VideoFrame::RGB32) { 36 if (frame->format() != media::VideoFrame::RGB32) {
38 LOG(INFO) << "DecoderVp8 only supports RGB32 as output"; 37 LOG(INFO) << "DecoderVp8 only supports RGB32 as output";
39 state_ = kError; 38 state_ = kError;
40 return; 39 return;
41 } 40 }
42 frame_ = frame; 41 frame_ = frame;
43 42
44 state_ = kReady; 43 state_ = kReady;
45 } 44 }
46 45
47 void DecoderVp8::DecodeBytes(const std::string& encoded_bytes) { 46 Decoder::DecodeResult DecoderVp8::DecodePacket(const VideoPacket* packet) {
48 DCHECK_EQ(kReady, state_); 47 DCHECK_EQ(kReady, state_);
49 48
50 // Initialize the codec as needed. 49 // Initialize the codec as needed.
51 if (!codec_) { 50 if (!codec_) {
52 codec_ = new vpx_codec_ctx_t(); 51 codec_ = new vpx_codec_ctx_t();
53 vpx_codec_err_t ret = 52 vpx_codec_err_t ret =
54 vpx_codec_dec_init( 53 vpx_codec_dec_init(
55 codec_, 54 codec_,
56 (const vpx_codec_iface_t*)media::GetVp8DxAlgoAddress(), NULL, 0); 55 (const vpx_codec_iface_t*)media::GetVp8DxAlgoAddress(), NULL, 0);
57 if (ret != VPX_CODEC_OK) { 56 if (ret != VPX_CODEC_OK) {
58 LOG(INFO) << "Cannot initialize codec."; 57 LOG(INFO) << "Cannot initialize codec.";
59 delete codec_; 58 delete codec_;
60 codec_ = NULL; 59 codec_ = NULL;
61 state_ = kError; 60 state_ = kError;
62 return; 61 return DECODE_ERROR;
63 } 62 }
64 } 63 }
65 64
66 // Do the actual decoding. 65 // Do the actual decoding.
67 vpx_codec_err_t ret = vpx_codec_decode( 66 vpx_codec_err_t ret = vpx_codec_decode(
68 codec_, reinterpret_cast<const uint8*>(encoded_bytes.data()), 67 codec_, reinterpret_cast<const uint8*>(packet->data().data()),
69 encoded_bytes.size(), NULL, 0); 68 packet->data().size(), NULL, 0);
70 if (ret != VPX_CODEC_OK) { 69 if (ret != VPX_CODEC_OK) {
71 LOG(INFO) << "Decoding failed:" << vpx_codec_err_to_string(ret) << "\n" 70 LOG(INFO) << "Decoding failed:" << vpx_codec_err_to_string(ret) << "\n"
72 << "Details: " << vpx_codec_error(codec_) << "\n" 71 << "Details: " << vpx_codec_error(codec_) << "\n"
73 << vpx_codec_error_detail(codec_); 72 << vpx_codec_error_detail(codec_);
74 return; 73 return DECODE_ERROR;
75 } 74 }
76 75
77 // Gets the decoded data. 76 // Gets the decoded data.
78 vpx_codec_iter_t iter = NULL; 77 vpx_codec_iter_t iter = NULL;
79 vpx_image_t* image = vpx_codec_get_frame(codec_, &iter); 78 vpx_image_t* image = vpx_codec_get_frame(codec_, &iter);
80 if (!image) { 79 if (!image) {
81 LOG(INFO) << "No video frame decoded"; 80 LOG(INFO) << "No video frame decoded";
82 return; 81 return DECODE_ERROR;
83 } 82 }
84 83
85 // Perform YUV conversion. 84 // Perform YUV conversion.
86 media::ConvertYUVToRGB32(image->planes[0], image->planes[1], image->planes[2], 85 media::ConvertYUVToRGB32(image->planes[0], image->planes[1], image->planes[2],
87 frame_->data(media::VideoFrame::kRGBPlane), 86 frame_->data(media::VideoFrame::kRGBPlane),
88 frame_->width(), frame_->height(), 87 frame_->width(), frame_->height(),
89 image->stride[0], image->stride[1], 88 image->stride[0], image->stride[1],
90 frame_->stride(media::VideoFrame::kRGBPlane), 89 frame_->stride(media::VideoFrame::kRGBPlane),
91 media::YV12); 90 media::YV12);
91 return DECODE_DONE;
92 }
93
94 void DecoderVp8::GetUpdatedRects(UpdatedRects* rects) {
92 } 95 }
93 96
94 void DecoderVp8::Reset() { 97 void DecoderVp8::Reset() {
95 frame_ = NULL; 98 frame_ = NULL;
96 state_ = kUninitialized; 99 state_ = kUninitialized;
97 } 100 }
98 101
99 bool DecoderVp8::IsReadyForData() { 102 bool DecoderVp8::IsReadyForData() {
100 return state_ == kReady; 103 return state_ == kReady;
101 } 104 }
102 105
103 VideoPacketFormat::Encoding DecoderVp8::Encoding() { 106 VideoPacketFormat::Encoding DecoderVp8::Encoding() {
104 return VideoPacketFormat::ENCODING_VP8; 107 return VideoPacketFormat::ENCODING_VP8;
105 } 108 }
106 109
107 } // namespace remoting 110 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/base/decoder_vp8.h ('k') | remoting/base/encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698