Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #ifndef CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ | 5 #ifndef CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ |
| 6 #define CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ | 6 #define CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 9 #include <queue> | |
| 10 | |
| 8 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 9 #include "base/mac/scoped_cftyperef.h" | 12 #include "base/mac/scoped_cftyperef.h" |
| 10 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/synchronization/lock.h" | |
| 13 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 14 #include "content/common/gpu/media/vt.h" | 19 #include "content/common/gpu/media/vt.h" |
| 15 #include "media/filters/h264_parser.h" | 20 #include "media/filters/h264_parser.h" |
| 16 #include "media/video/video_decode_accelerator.h" | 21 #include "media/video/video_decode_accelerator.h" |
| 17 #include "ui/gfx/geometry/size.h" | 22 #include "ui/gfx/geometry/size.h" |
| 18 #include "ui/gl/gl_context_cgl.h" | 23 #include "ui/gl/gl_context_cgl.h" |
| 19 | 24 |
| 20 namespace base { | 25 namespace base { |
| 21 class SingleThreadTaskRunner; | 26 class SingleThreadTaskRunner; |
| 22 } // namespace base | 27 } // namespace base |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 46 virtual bool CanDecodeOnIOThread() OVERRIDE; | 51 virtual bool CanDecodeOnIOThread() OVERRIDE; |
| 47 | 52 |
| 48 // Called by VideoToolbox when a frame is decoded. | 53 // Called by VideoToolbox when a frame is decoded. |
| 49 void Output( | 54 void Output( |
| 50 int32_t bitstream_id, | 55 int32_t bitstream_id, |
| 51 OSStatus status, | 56 OSStatus status, |
| 52 VTDecodeInfoFlags info_flags, | 57 VTDecodeInfoFlags info_flags, |
| 53 CVImageBufferRef image_buffer); | 58 CVImageBufferRef image_buffer); |
| 54 | 59 |
| 55 private: | 60 private: |
| 61 struct DecodedFrame { | |
| 62 DecodedFrame(uint32_t bitstream_id, CVImageBufferRef image_buffer) | |
| 63 : bitstream_id(bitstream_id), image_buffer(image_buffer) { | |
| 64 } | |
| 65 | |
| 66 int32_t bitstream_id; | |
| 67 CVImageBufferRef image_buffer; | |
| 68 }; | |
| 69 | |
| 56 // Configure a VideoToolbox decompression session from parameter set NALUs. | 70 // Configure a VideoToolbox decompression session from parameter set NALUs. |
| 57 void ConfigureDecoder( | 71 void ConfigureDecoder( |
| 58 const std::vector<const uint8_t*>& nalu_data_ptrs, | 72 const std::vector<const uint8_t*>& nalu_data_ptrs, |
| 59 const std::vector<size_t>& nalu_data_sizes); | 73 const std::vector<size_t>& nalu_data_sizes); |
| 60 | 74 |
| 61 // Decode a frame of bitstream. | 75 // Decode a frame of bitstream. |
| 62 void DecodeTask(const media::BitstreamBuffer); | 76 void DecodeTask(const media::BitstreamBuffer); |
| 63 | 77 |
| 78 // Send decoded frames if possible. | |
| 79 void SendPictures(); | |
| 80 | |
| 81 // | |
| 82 // GPU thread state. | |
| 83 // | |
| 64 CGLContextObj cgl_context_; | 84 CGLContextObj cgl_context_; |
| 65 media::VideoDecodeAccelerator::Client* client_; | 85 // Texture IDs of assigned pictures. |
| 66 base::Thread decoder_thread_; | 86 std::map<int32_t, int32_t> texture_ids_; |
|
scherkus (not reviewing)
2014/07/16 18:18:51
Chromium uses int32 w/o the _t
sandersd (OOO until July 31)
2014/07/17 00:22:22
My understanding is those types are deprecated.
h
scherkus (not reviewing)
2014/07/17 02:08:25
huh! go figure!
https://code.google.com/p/chromiu
| |
| 87 // Pictures ready to be used. | |
| 88 std::queue<int32_t> picture_ids_; | |
| 89 // CVImageBuffers retained while they back textures. | |
| 90 std::map<int32_t, base::ScopedCFTypeRef<CVImageBufferRef>> retained_images_; | |
| 67 | 91 |
| 68 // Decoder configuration (used only on decoder thread). | 92 // |
| 93 // Decoder thread state. | |
| 94 // | |
| 69 VTDecompressionOutputCallbackRecord callback_; | 95 VTDecompressionOutputCallbackRecord callback_; |
| 70 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_; | 96 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_; |
| 71 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_; | 97 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_; |
| 72 media::H264Parser parser_; | 98 media::H264Parser parser_; |
| 73 gfx::Size coded_size_; | 99 gfx::Size coded_size_; |
| 74 | 100 |
| 75 // Member variables should appear before the WeakPtrFactory, to ensure | 101 // |
| 76 // that any WeakPtrs to Controller are invalidated before its members | 102 // Lock-protected shared state. |
| 77 // variable's destructors are executed, rendering them invalid. | 103 // |
| 104 base::Lock lock_; | |
| 105 int32_t frames_pending_decode_; | |
|
scherkus (not reviewing)
2014/07/16 18:18:51
for a count that shouldn't be negative, something
sandersd (OOO until July 31)
2014/07/17 00:22:22
Done.
| |
| 106 std::queue<DecodedFrame> decoded_frames_; | |
| 107 | |
| 108 // | |
| 109 // Unprotected shared state (set up and torn down on GPU thread). | |
| 110 // | |
| 111 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; | |
| 112 scoped_ptr<base::WeakPtrFactory<media::VideoDecodeAccelerator::Client>> | |
| 113 weak_client_factory_; | |
| 114 | |
| 115 // Declared after decoder thread state so that the thread will be stopped | |
| 116 // before its state is deleted. | |
| 117 base::Thread decoder_thread_; | |
| 118 | |
| 119 // Declared last so that tasks are not posted after deletion starts. | |
| 78 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; | 120 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; |
| 79 | 121 |
| 80 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); | 122 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); |
| 81 }; | 123 }; |
| 82 | 124 |
| 83 } // namespace content | 125 } // namespace content |
| 84 | 126 |
| 85 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ | 127 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ |
| OLD | NEW |