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

Side by Side Diff: media/gpu/fake_video_decode_accelerator.cc

Issue 2061823003: media: Drop "media::" in media/gpu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: work around clang format by adding an empty line Created 4 years, 6 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
« no previous file with comments | « media/gpu/fake_video_decode_accelerator.h ('k') | media/gpu/generic_v4l2_device.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "media/gpu/fake_video_decode_accelerator.h" 5 #include "media/gpu/fake_video_decode_accelerator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 10 matching lines...) Expand all
21 #include "ui/gl/gl_surface_glx.h" 21 #include "ui/gl/gl_surface_glx.h"
22 22
23 namespace media { 23 namespace media {
24 24
25 static const uint32_t kDefaultTextureTarget = GL_TEXTURE_2D; 25 static const uint32_t kDefaultTextureTarget = GL_TEXTURE_2D;
26 // Must be at least 2 since the rendering helper will switch between textures 26 // Must be at least 2 since the rendering helper will switch between textures
27 // and if there is only one, it will wait for the next one that will never come. 27 // and if there is only one, it will wait for the next one that will never come.
28 // Must also be an even number as otherwise there won't be the same amount of 28 // Must also be an even number as otherwise there won't be the same amount of
29 // white and black frames. 29 // white and black frames.
30 static const unsigned int kNumBuffers = 30 static const unsigned int kNumBuffers =
31 media::limits::kMaxVideoFrames + (media::limits::kMaxVideoFrames & 1u); 31 limits::kMaxVideoFrames + (limits::kMaxVideoFrames & 1u);
32 32
33 FakeVideoDecodeAccelerator::FakeVideoDecodeAccelerator( 33 FakeVideoDecodeAccelerator::FakeVideoDecodeAccelerator(
34 const gfx::Size& size, 34 const gfx::Size& size,
35 const MakeGLContextCurrentCallback& make_context_current_cb) 35 const MakeGLContextCurrentCallback& make_context_current_cb)
36 : child_task_runner_(base::ThreadTaskRunnerHandle::Get()), 36 : child_task_runner_(base::ThreadTaskRunnerHandle::Get()),
37 client_(NULL), 37 client_(NULL),
38 make_context_current_cb_(make_context_current_cb), 38 make_context_current_cb_(make_context_current_cb),
39 frame_buffer_size_(size), 39 frame_buffer_size_(size),
40 flushing_(false), 40 flushing_(false),
41 weak_this_factory_(this) {} 41 weak_this_factory_(this) {}
42 42
43 FakeVideoDecodeAccelerator::~FakeVideoDecodeAccelerator() {} 43 FakeVideoDecodeAccelerator::~FakeVideoDecodeAccelerator() {}
44 44
45 bool FakeVideoDecodeAccelerator::Initialize(const Config& config, 45 bool FakeVideoDecodeAccelerator::Initialize(const Config& config,
46 Client* client) { 46 Client* client) {
47 DCHECK(child_task_runner_->BelongsToCurrentThread()); 47 DCHECK(child_task_runner_->BelongsToCurrentThread());
48 if (config.profile == media::VIDEO_CODEC_PROFILE_UNKNOWN) { 48 if (config.profile == VIDEO_CODEC_PROFILE_UNKNOWN) {
49 LOG(ERROR) << "unknown codec profile"; 49 LOG(ERROR) << "unknown codec profile";
50 return false; 50 return false;
51 } 51 }
52 if (config.is_encrypted) { 52 if (config.is_encrypted) {
53 NOTREACHED() << "encrypted streams are not supported"; 53 NOTREACHED() << "encrypted streams are not supported";
54 return false; 54 return false;
55 } 55 }
56 56
57 // V4L2VideoDecodeAccelerator waits until first decode call to ask for buffers 57 // V4L2VideoDecodeAccelerator waits until first decode call to ask for buffers
58 // This class asks for it on initialization instead. 58 // This class asks for it on initialization instead.
59 client_ = client; 59 client_ = client;
60 client_->ProvidePictureBuffers(kNumBuffers, PIXEL_FORMAT_UNKNOWN, 1, 60 client_->ProvidePictureBuffers(kNumBuffers, PIXEL_FORMAT_UNKNOWN, 1,
61 frame_buffer_size_, kDefaultTextureTarget); 61 frame_buffer_size_, kDefaultTextureTarget);
62 return true; 62 return true;
63 } 63 }
64 64
65 void FakeVideoDecodeAccelerator::Decode( 65 void FakeVideoDecodeAccelerator::Decode(
66 const media::BitstreamBuffer& bitstream_buffer) { 66 const BitstreamBuffer& bitstream_buffer) {
67 // We won't really read from the bitstream_buffer, close the handle. 67 // We won't really read from the bitstream_buffer, close the handle.
68 if (base::SharedMemory::IsHandleValid(bitstream_buffer.handle())) 68 if (base::SharedMemory::IsHandleValid(bitstream_buffer.handle()))
69 base::SharedMemory::CloseHandle(bitstream_buffer.handle()); 69 base::SharedMemory::CloseHandle(bitstream_buffer.handle());
70 70
71 if (bitstream_buffer.id() < 0) { 71 if (bitstream_buffer.id() < 0) {
72 LOG(ERROR) << "Invalid bitstream: id=" << bitstream_buffer.id(); 72 LOG(ERROR) << "Invalid bitstream: id=" << bitstream_buffer.id();
73 client_->NotifyError(INVALID_ARGUMENT); 73 client_->NotifyError(INVALID_ARGUMENT);
74 return; 74 return;
75 } 75 }
76 76
77 int bitstream_buffer_id = bitstream_buffer.id(); 77 int bitstream_buffer_id = bitstream_buffer.id();
78 queued_bitstream_ids_.push(bitstream_buffer_id); 78 queued_bitstream_ids_.push(bitstream_buffer_id);
79 child_task_runner_->PostTask( 79 child_task_runner_->PostTask(
80 FROM_HERE, base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady, 80 FROM_HERE, base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady,
81 weak_this_factory_.GetWeakPtr())); 81 weak_this_factory_.GetWeakPtr()));
82 } 82 }
83 83
84 // Similar to UseOutputBitstreamBuffer for the encode accelerator. 84 // Similar to UseOutputBitstreamBuffer for the encode accelerator.
85 void FakeVideoDecodeAccelerator::AssignPictureBuffers( 85 void FakeVideoDecodeAccelerator::AssignPictureBuffers(
86 const std::vector<media::PictureBuffer>& buffers) { 86 const std::vector<PictureBuffer>& buffers) {
87 DCHECK(buffers.size() == kNumBuffers); 87 DCHECK(buffers.size() == kNumBuffers);
88 DCHECK(!(buffers.size() % 2)); 88 DCHECK(!(buffers.size() % 2));
89 89
90 // Save buffers and mark all buffers as ready for use. 90 // Save buffers and mark all buffers as ready for use.
91 std::unique_ptr<uint8_t[]> white_data( 91 std::unique_ptr<uint8_t[]> white_data(
92 new uint8_t[frame_buffer_size_.width() * frame_buffer_size_.height() * 92 new uint8_t[frame_buffer_size_.width() * frame_buffer_size_.height() *
93 4]); 93 4]);
94 memset(white_data.get(), UINT8_MAX, 94 memset(white_data.get(), UINT8_MAX,
95 frame_buffer_size_.width() * frame_buffer_size_.height() * 4); 95 frame_buffer_size_.width() * frame_buffer_size_.height() * 4);
96 std::unique_ptr<uint8_t[]> black_data( 96 std::unique_ptr<uint8_t[]> black_data(
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 if (flushing_ && queued_bitstream_ids_.empty()) { 162 if (flushing_ && queued_bitstream_ids_.empty()) {
163 flushing_ = false; 163 flushing_ = false;
164 client_->NotifyFlushDone(); 164 client_->NotifyFlushDone();
165 } 165 }
166 while (!free_output_buffers_.empty() && !queued_bitstream_ids_.empty()) { 166 while (!free_output_buffers_.empty() && !queued_bitstream_ids_.empty()) {
167 int bitstream_id = queued_bitstream_ids_.front(); 167 int bitstream_id = queued_bitstream_ids_.front();
168 queued_bitstream_ids_.pop(); 168 queued_bitstream_ids_.pop();
169 int buffer_id = free_output_buffers_.front(); 169 int buffer_id = free_output_buffers_.front();
170 free_output_buffers_.pop(); 170 free_output_buffers_.pop();
171 171
172 const media::Picture picture = media::Picture( 172 const Picture picture =
173 buffer_id, bitstream_id, gfx::Rect(frame_buffer_size_), false); 173 Picture(buffer_id, bitstream_id, gfx::Rect(frame_buffer_size_), false);
174 client_->PictureReady(picture); 174 client_->PictureReady(picture);
175 // Bitstream no longer needed. 175 // Bitstream no longer needed.
176 client_->NotifyEndOfBitstreamBuffer(bitstream_id); 176 client_->NotifyEndOfBitstreamBuffer(bitstream_id);
177 if (flushing_ && queued_bitstream_ids_.empty()) { 177 if (flushing_ && queued_bitstream_ids_.empty()) {
178 flushing_ = false; 178 flushing_ = false;
179 client_->NotifyFlushDone(); 179 client_->NotifyFlushDone();
180 } 180 }
181 } 181 }
182 } 182 }
183 183
184 } // namespace media 184 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/fake_video_decode_accelerator.h ('k') | media/gpu/generic_v4l2_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698