Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/gpu/media/fake_gl_video_decode_engine.h" | |
| 6 | |
| 7 #include "app/gfx/gl/gl_bindings.h" | |
| 8 | |
| 9 FakeGlVideoDecodeEngine::FakeGlVideoDecodeEngine() | |
| 10 : width_(0), | |
| 11 height_(0), | |
| 12 handler_(NULL) { | |
| 13 } | |
| 14 | |
| 15 FakeGlVideoDecodeEngine::~FakeGlVideoDecodeEngine() { | |
| 16 } | |
| 17 | |
| 18 void FakeGlVideoDecodeEngine::Initialize( | |
| 19 MessageLoop* message_loop, | |
| 20 media::VideoDecodeEngine::EventHandler* event_handler, | |
| 21 const media::VideoCodecConfig& config) { | |
| 22 handler_ = event_handler; | |
| 23 width_ = config.width; | |
| 24 height_ = config.height; | |
| 25 | |
| 26 media::VideoCodecInfo info; | |
| 27 info.success = true; | |
| 28 info.provides_buffers = true; | |
| 29 info.stream_info.surface_format = media::VideoFrame::RGBA; | |
| 30 info.stream_info.surface_type = media::VideoFrame::TYPE_GL_TEXTURE; | |
| 31 info.stream_info.surface_width = width_; | |
| 32 info.stream_info.surface_height = height_; | |
| 33 | |
| 34 // TODO(hclam): When we have VideoDecodeContext we should use it to allocate | |
| 35 // video frames. | |
| 36 handler_->OnInitializeComplete(info); | |
| 37 } | |
| 38 | |
| 39 void FakeGlVideoDecodeEngine::Uninitialize() { | |
| 40 handler_->OnUninitializeComplete(); | |
| 41 } | |
| 42 | |
| 43 void FakeGlVideoDecodeEngine::Flush() { | |
| 44 handler_->OnFlushComplete(); | |
| 45 } | |
| 46 | |
| 47 void FakeGlVideoDecodeEngine::Seek() { | |
| 48 handler_->OnSeekComplete(); | |
| 49 } | |
| 50 | |
| 51 void FakeGlVideoDecodeEngine::ConsumeVideoSample( | |
| 52 scoped_refptr<media::Buffer> buffer) { | |
| 53 // Don't care. | |
| 54 } | |
| 55 | |
| 56 void FakeGlVideoDecodeEngine::ProduceVideoFrame( | |
| 57 scoped_refptr<media::VideoFrame> frame) { | |
| 58 // Fake that we need some buffer. | |
| 59 handler_->ProduceVideoSample(NULL); | |
| 60 | |
| 61 int size = width_ * height_ * 4; | |
| 62 scoped_array<uint8> buffer(new uint8[size]); | |
| 63 memset(buffer.get(), 0, size); | |
| 64 | |
| 65 uint8* row = buffer.get(); | |
| 66 static int seed = 0; | |
|
scherkus (not reviewing)
2010/09/13 07:19:23
just use a uint8 and let it overflow?
but to be h
| |
| 67 | |
| 68 for (int y = 0; y < height_; ++y) { | |
| 69 int offset = y % 3; | |
| 70 for (int x = 0; x < width_; ++x) { | |
| 71 row[x * 4 + offset] = seed++; | |
| 72 seed &= 255; | |
| 73 } | |
| 74 row += width_ * 4; | |
| 75 } | |
| 76 ++seed; | |
| 77 | |
| 78 // Assume we are in the right context and then upload the content to the | |
| 79 // texture. | |
| 80 glBindTexture(GL_TEXTURE_2D, | |
| 81 frame->gl_texture(media::VideoFrame::kRGBPlane)); | |
| 82 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width_, height_, 0, GL_RGBA, | |
| 83 GL_UNSIGNED_BYTE, buffer.get()); | |
| 84 | |
| 85 // We have done generating data to the frame so give it to the handler. | |
| 86 // TODO(hclam): Advance the timestamp every time we call this method. | |
| 87 handler_->ConsumeVideoFrame(frame); | |
| 88 } | |
| OLD | NEW |