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

Side by Side Diff: content/gpu/media/fake_gl_video_decode_engine.cc

Issue 6793054: Moved code that runs in both the browser and GPU process from content/gpu to content/common/gpu. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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
(Empty)
1 // Copyright (c) 2011 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/gpu/media/fake_gl_video_decode_engine.h"
6
7 #include "media/base/limits.h"
8 #include "media/base/video_frame.h"
9 #include "media/video/video_decode_context.h"
10
11 FakeGlVideoDecodeEngine::FakeGlVideoDecodeEngine()
12 : width_(0),
13 height_(0),
14 handler_(NULL),
15 context_(NULL) {
16 }
17
18 FakeGlVideoDecodeEngine::~FakeGlVideoDecodeEngine() {
19 }
20
21 void FakeGlVideoDecodeEngine::Initialize(
22 MessageLoop* message_loop,
23 media::VideoDecodeEngine::EventHandler* event_handler,
24 media::VideoDecodeContext* context,
25 const media::VideoCodecConfig& config) {
26 handler_ = event_handler;
27 context_ = context;
28 width_ = config.width();
29 height_ = config.height();
30
31 // Create an internal VideoFrame that we can write to. This is going to be
32 // uploaded through VideoDecodeContext.
33 media::VideoFrame::CreateFrame(
34 media::VideoFrame::RGBA, width_, height_, base::TimeDelta(),
35 base::TimeDelta(), &internal_frame_);
36 memset(internal_frame_->data(media::VideoFrame::kRGBPlane), 0,
37 height_ * internal_frame_->stride(media::VideoFrame::kRGBPlane));
38
39 // Use VideoDecodeContext to allocate VideoFrame that can be consumed by
40 // external body.
41 // TODO(hclam): It is horrible to use constants everywhere in the code!
42 // The number of frames come from VideoRendererBase in the renderer, this is
43 // horrible!
44 context_->AllocateVideoFrames(
45 media::Limits::kMaxVideoFrames, width_, height_, media::VideoFrame::RGBA,
46 &external_frames_,
47 NewRunnableMethod(this,
48 &FakeGlVideoDecodeEngine::AllocationCompleteTask));
49 }
50
51 void FakeGlVideoDecodeEngine::AllocationCompleteTask() {
52 DCHECK(media::Limits::kMaxVideoFrames == external_frames_.size());
53 DCHECK_EQ(media::VideoFrame::TYPE_GL_TEXTURE, external_frames_[0]->type());
54
55 media::VideoCodecInfo info;
56 info.success = true;
57 info.provides_buffers = true;
58 info.stream_info.surface_format = media::VideoFrame::RGBA;
59 info.stream_info.surface_type = media::VideoFrame::TYPE_GL_TEXTURE;
60 info.stream_info.surface_width = width_;
61 info.stream_info.surface_height = height_;
62 handler_->OnInitializeComplete(info);
63 }
64
65 void FakeGlVideoDecodeEngine::Uninitialize() {
66 handler_->OnUninitializeComplete();
67 }
68
69 void FakeGlVideoDecodeEngine::Flush() {
70 handler_->OnFlushComplete();
71 }
72
73 void FakeGlVideoDecodeEngine::Seek() {
74 // TODO(hclam): This is a big hack to continue playing because we need to
75 // *push* decoded frames to downstream. The model used in VideoRendererBase
76 // to wait for *push* is flawed.
77 for (size_t i = 0; i < external_frames_.size(); ++i)
78 handler_->ConsumeVideoFrame(external_frames_[i], dummy_stats_);
79 handler_->OnSeekComplete();
80 }
81
82 void FakeGlVideoDecodeEngine::ConsumeVideoSample(
83 scoped_refptr<media::Buffer> sample) {
84 DCHECK(!pending_frames_.empty());
85 scoped_refptr<media::VideoFrame> frame = pending_frames_.front();
86 pending_frames_.pop();
87
88 frame->SetDuration(sample->GetDuration());
89 frame->SetTimestamp(sample->GetTimestamp());
90
91 // Generate a pattern to the internal frame and then uploads it.
92 int size = width_ * height_ * 4;
93 scoped_array<uint8> buffer(new uint8[size]);
94 memset(buffer.get(), 255, size);
95
96 uint8* row = internal_frame_->data(media::VideoFrame::kRGBPlane);
97 static int seed = 0;
98
99 for (int y = 0; y < height_; ++y) {
100 int offset = y % 3;
101 for (int x = 0; x < width_; ++x) {
102 row[x * 4 + offset + 1] = seed++;
103 seed &= 255;
104 }
105 row += width_ * 4;
106 }
107 ++seed;
108
109 // After we have filled the content upload the internal frame to the
110 // VideoFrame allocated through VideoDecodeContext.
111 context_->ConvertToVideoFrame(
112 internal_frame_, frame,
113 NewRunnableMethod(this, &FakeGlVideoDecodeEngine::UploadCompleteTask,
114 frame));
115 }
116
117 void FakeGlVideoDecodeEngine::ProduceVideoFrame(
118 scoped_refptr<media::VideoFrame> frame) {
119 // Enqueue the frame to the pending queue.
120 pending_frames_.push(frame);
121
122 // Fake that we need some buffer.
123 handler_->ProduceVideoSample(NULL);
124 }
125
126 void FakeGlVideoDecodeEngine::UploadCompleteTask(
127 scoped_refptr<media::VideoFrame> frame) {
128 // |frame| is the upload target. We can immediately send this frame out.
129 handler_->ConsumeVideoFrame(frame, dummy_stats_);
130 }
131
132 DISABLE_RUNNABLE_METHOD_REFCOUNT(FakeGlVideoDecodeEngine);
OLDNEW
« no previous file with comments | « content/gpu/media/fake_gl_video_decode_engine.h ('k') | content/gpu/media/fake_gl_video_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698