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

Side by Side Diff: content/common/gpu/media/mac_video_decode_accelerator.mm

Issue 11225045: Move a bunch of content\common code into the content namespace. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/common/gpu/media/mac_video_decode_accelerator.h" 5 #include "content/common/gpu/media/mac_video_decode_accelerator.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #import "base/mac/foundation_util.h" 9 #import "base/mac/foundation_util.h"
10 #import "base/memory/ref_counted_memory.h" 10 #import "base/memory/ref_counted_memory.h"
11 #import "base/message_loop.h" 11 #import "base/message_loop.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/native_library.h" 13 #include "base/native_library.h"
14 #include "ui/surface/io_surface_support_mac.h" 14 #include "ui/surface/io_surface_support_mac.h"
15 #include "ui/gfx/video_decode_acceleration_support_mac.h" 15 #include "ui/gfx/video_decode_acceleration_support_mac.h"
16 16
17 namespace content {
18
17 // Helper macros for dealing with failure. If |result| evaluates false, emit 19 // Helper macros for dealing with failure. If |result| evaluates false, emit
18 // |log| to ERROR, register |error| with the decoder, and return |ret_val| 20 // |log| to ERROR, register |error| with the decoder, and return |ret_val|
19 // (which may be omitted for functions that return void). 21 // (which may be omitted for functions that return void).
20 #define RETURN_ON_FAILURE(result, log, error, ret_val) \ 22 #define RETURN_ON_FAILURE(result, log, error, ret_val) \
21 do { \ 23 do { \
22 if (!(result)) { \ 24 if (!(result)) { \
23 DLOG(ERROR) << log; \ 25 DLOG(ERROR) << log; \
24 StopOnError(error); \ 26 StopOnError(error); \
25 return ret_val; \ 27 return ret_val; \
26 } \ 28 } \
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 RETURN_ON_FAILURE(client_, 122 RETURN_ON_FAILURE(client_,
121 "Call to Decode() during invalid state.", ILLEGAL_STATE,); 123 "Call to Decode() during invalid state.", ILLEGAL_STATE,);
122 124
123 base::SharedMemory memory(bitstream_buffer.handle(), true); 125 base::SharedMemory memory(bitstream_buffer.handle(), true);
124 RETURN_ON_FAILURE(memory.Map(bitstream_buffer.size()), 126 RETURN_ON_FAILURE(memory.Map(bitstream_buffer.size()),
125 "Failed to SharedMemory::Map().", UNREADABLE_INPUT,); 127 "Failed to SharedMemory::Map().", UNREADABLE_INPUT,);
126 128
127 h264_parser_.SetStream(static_cast<const uint8_t*>(memory.memory()), 129 h264_parser_.SetStream(static_cast<const uint8_t*>(memory.memory()),
128 bitstream_buffer.size()); 130 bitstream_buffer.size());
129 while (true) { 131 while (true) {
130 content::H264NALU nalu; 132 H264NALU nalu;
131 content::H264Parser::Result result = h264_parser_.AdvanceToNextNALU(&nalu); 133 H264Parser::Result result = h264_parser_.AdvanceToNextNALU(&nalu);
132 if (result == content::H264Parser::kEOStream) { 134 if (result == H264Parser::kEOStream) {
133 if (bitstream_nalu_count_.count(bitstream_buffer.id()) == 0) { 135 if (bitstream_nalu_count_.count(bitstream_buffer.id()) == 0) {
134 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 136 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
135 &MacVideoDecodeAccelerator::NotifyInputBufferRead, 137 &MacVideoDecodeAccelerator::NotifyInputBufferRead,
136 base::AsWeakPtr(this), bitstream_buffer.id())); 138 base::AsWeakPtr(this), bitstream_buffer.id()));
137 } 139 }
138 return; 140 return;
139 } 141 }
140 RETURN_ON_FAILURE(result == content::H264Parser::kOk, 142 RETURN_ON_FAILURE(result == H264Parser::kOk,
141 "Unable to parse bitstream.", UNREADABLE_INPUT,); 143 "Unable to parse bitstream.", UNREADABLE_INPUT,);
142 if (!did_build_config_record_) { 144 if (!did_build_config_record_) {
143 std::vector<uint8_t> config_record; 145 std::vector<uint8_t> config_record;
144 RETURN_ON_FAILURE(config_record_builder_.ProcessNALU(&h264_parser_, nalu, 146 RETURN_ON_FAILURE(config_record_builder_.ProcessNALU(&h264_parser_, nalu,
145 &config_record), 147 &config_record),
146 "Unable to build AVC configuraiton record.", 148 "Unable to build AVC configuraiton record.",
147 UNREADABLE_INPUT,); 149 UNREADABLE_INPUT,);
148 if (!config_record.empty()) { 150 if (!config_record.empty()) {
149 did_build_config_record_ = true; 151 did_build_config_record_ = true;
150 if (!CreateDecoder(config_record)) 152 if (!CreateDecoder(config_record))
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 &extra_data[0], extra_data.size()); 303 &extra_data[0], extra_data.size());
302 RETURN_ON_FAILURE(status == gfx::VideoDecodeAccelerationSupport::SUCCESS, 304 RETURN_ON_FAILURE(status == gfx::VideoDecodeAccelerationSupport::SUCCESS,
303 "Creating video decoder failed with error: " << status, 305 "Creating video decoder failed with error: " << status,
304 PLATFORM_FAILURE, false); 306 PLATFORM_FAILURE, false);
305 307
306 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 308 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
307 &MacVideoDecodeAccelerator::RequestPictures, base::AsWeakPtr(this))); 309 &MacVideoDecodeAccelerator::RequestPictures, base::AsWeakPtr(this)));
308 return true; 310 return true;
309 } 311 }
310 312
311 void MacVideoDecodeAccelerator::DecodeNALU(const content::H264NALU& nalu, 313 void MacVideoDecodeAccelerator::DecodeNALU(const H264NALU& nalu,
312 int32 bitstream_buffer_id) { 314 int32 bitstream_buffer_id) {
313 // Assume the NALU length field size is 4 bytes. 315 // Assume the NALU length field size is 4 bytes.
314 const int kNALULengthFieldSize = 4; 316 const int kNALULengthFieldSize = 4;
315 std::vector<uint8_t> data(kNALULengthFieldSize + nalu.size); 317 std::vector<uint8_t> data(kNALULengthFieldSize + nalu.size);
316 318
317 // Store the buffer size at the beginning of the buffer as the decoder 319 // Store the buffer size at the beginning of the buffer as the decoder
318 // expects. 320 // expects.
319 for (size_t i = 0; i < kNALULengthFieldSize; ++i) { 321 for (size_t i = 0; i < kNALULengthFieldSize; ++i) {
320 size_t shift = kNALULengthFieldSize * 8 - (i + 1) * 8; 322 size_t shift = kNALULengthFieldSize * 8 - (i + 1) * 8;
321 data[i] = (nalu.size >> shift) & 0xff; 323 data[i] = (nalu.size >> shift) & 0xff;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 } 373 }
372 374
373 MacVideoDecodeAccelerator::UsedPictureInfo::~UsedPictureInfo() { 375 MacVideoDecodeAccelerator::UsedPictureInfo::~UsedPictureInfo() {
374 } 376 }
375 377
376 MacVideoDecodeAccelerator::DecodedImageInfo::DecodedImageInfo() { 378 MacVideoDecodeAccelerator::DecodedImageInfo::DecodedImageInfo() {
377 } 379 }
378 380
379 MacVideoDecodeAccelerator::DecodedImageInfo::~DecodedImageInfo() { 381 MacVideoDecodeAccelerator::DecodedImageInfo::~DecodedImageInfo() {
380 } 382 }
383
384 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/media/mac_video_decode_accelerator.h ('k') | content/common/gpu/media/omx_video_decode_accelerator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698