Commit e68e3228 authored by sandersd@chromium.org's avatar sandersd@chromium.org

Implement actually decoding frames in VTVideoDecodeAccelerator.

This adds translation from Annex B to AVCC format along with decoding
frames and binding them to textures.

It seems that kVTDecodeFrame_EnableTemporalProcessing is just a
suggestion to VideoToolbox, and one that it ignores. That means that,
for now, this code only outputs frames in the correct order for I-frame
only video.

BUG=133828

Review URL: https://codereview.chromium.org/397883002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287451 0039d316-1c4b-4281-b951-d872f2087c98
parent 65a6ec4a
......@@ -370,11 +370,12 @@ void GpuVideoDecodeAccelerator::OnAssignPictureBuffers(
NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT);
return;
}
if (texture_target_ == GL_TEXTURE_EXTERNAL_OES) {
// GL_TEXTURE_EXTERNAL_OES textures have their dimensions defined by the
// underlying EGLImage. Use |texture_dimensions_| for this size.
if (texture_target_ == GL_TEXTURE_EXTERNAL_OES ||
texture_target_ == GL_TEXTURE_RECTANGLE) {
// These textures have their dimensions defined by the underlying storage.
// Use |texture_dimensions_| for this size.
texture_manager->SetLevelInfo(texture_ref,
GL_TEXTURE_EXTERNAL_OES,
texture_target_,
0,
0,
texture_dimensions_.width(),
......
......@@ -58,6 +58,12 @@ typedef OSStatus (*CMSampleBufferMakeDataReadyCallback)(
typedef struct __CVBuffer *CVBufferRef;
typedef CVBufferRef CVImageBufferRef;
typedef uint32_t VTDecodeFrameFlags;
enum {
kVTDecodeFrame_EnableAsynchronousDecompression = 1 << 0,
kVTDecodeFrame_DoNotOutputFrame = 1 << 1,
kVTDecodeFrame_1xRealTimePlayback = 1 << 2,
kVTDecodeFrame_EnableTemporalProcessing = 1 << 3,
};
typedef UInt32 VTDecodeInfoFlags;
typedef struct OpaqueVTDecompressionSession* VTDecompressionSessionRef;
......
......@@ -5,7 +5,11 @@
#ifndef CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_
#define CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_
#include "base/basictypes.h"
#include <stdint.h>
#include <map>
#include <queue>
#include "base/mac/scoped_cftyperef.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
......@@ -45,38 +49,74 @@ class VTVideoDecodeAccelerator
virtual void Destroy() OVERRIDE;
virtual bool CanDecodeOnIOThread() OVERRIDE;
// Called by VideoToolbox when a frame is decoded.
// Called by OutputThunk() when VideoToolbox finishes decoding a frame.
void Output(
int32_t bitstream_id,
OSStatus status,
VTDecodeInfoFlags info_flags,
CVImageBufferRef image_buffer);
private:
// Configure a VideoToolbox decompression session from parameter set NALUs.
struct DecodedFrame {
DecodedFrame(int32_t bitstream_id, CVImageBufferRef image_buffer);
~DecodedFrame();
int32_t bitstream_id;
base::ScopedCFTypeRef<CVImageBufferRef> image_buffer;
};
// Methods for interacting with VideoToolbox. Run on |decoder_thread_|.
void ConfigureDecoder(
const std::vector<const uint8_t*>& nalu_data_ptrs,
const std::vector<size_t>& nalu_data_sizes);
// Decode a frame of bitstream.
void DecodeTask(const media::BitstreamBuffer);
// Methods for interacting with |client_|. Run on |gpu_task_runner_|.
void OutputTask(DecodedFrame frame);
void SizeChangedTask(gfx::Size coded_size);
void SendPictures();
//
// GPU thread state.
//
CGLContextObj cgl_context_;
media::VideoDecodeAccelerator::Client* client_;
base::Thread decoder_thread_;
gfx::Size texture_size_;
// Decoder configuration (used only on decoder thread).
// Texture IDs of pictures.
// TODO(sandersd): A single map of structs holding picture data.
std::map<int32_t, uint32_t> texture_ids_;
// Pictures ready to be rendered to.
std::queue<int32_t> available_picture_ids_;
// Decoded frames ready to render.
std::queue<DecodedFrame> decoded_frames_;
// Image buffers kept alive while they are bound to pictures.
std::map<int32_t, base::ScopedCFTypeRef<CVImageBufferRef>> picture_bindings_;
//
// Decoder thread state.
//
VTDecompressionOutputCallbackRecord callback_;
base::ScopedCFTypeRef<CMFormatDescriptionRef> format_;
base::ScopedCFTypeRef<VTDecompressionSessionRef> session_;
media::H264Parser parser_;
gfx::Size coded_size_;
// Member variables should appear before the WeakPtrFactory, to ensure
// that any WeakPtrs to Controller are invalidated before its members
// variable's destructors are executed, rendering them invalid.
//
// Unprotected shared state (set up and torn down on GPU thread).
//
scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_;
// This WeakPtrFactory does not need to be last as its pointers are bound to
// the same thread it is destructed on (the GPU thread).
base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_;
// Declared last to ensure that all decoder thread tasks complete before any
// state is destructed.
base::Thread decoder_thread_;
DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment