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 "base/basictypes.h" | 8 #include <stdint.h> |
| 9 |
| 10 #include <map> |
| 11 #include <queue> |
| 12 |
9 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
10 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.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" |
13 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
14 #include "content/common/gpu/media/vt.h" | 18 #include "content/common/gpu/media/vt.h" |
15 #include "media/filters/h264_parser.h" | 19 #include "media/filters/h264_parser.h" |
16 #include "media/video/video_decode_accelerator.h" | 20 #include "media/video/video_decode_accelerator.h" |
17 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" |
18 #include "ui/gl/gl_context_cgl.h" | 22 #include "ui/gl/gl_context_cgl.h" |
(...skipping 19 matching lines...) Expand all Loading... |
38 Client* client) OVERRIDE; | 42 Client* client) OVERRIDE; |
39 virtual void Decode(const media::BitstreamBuffer& bitstream) OVERRIDE; | 43 virtual void Decode(const media::BitstreamBuffer& bitstream) OVERRIDE; |
40 virtual void AssignPictureBuffers( | 44 virtual void AssignPictureBuffers( |
41 const std::vector<media::PictureBuffer>& pictures) OVERRIDE; | 45 const std::vector<media::PictureBuffer>& pictures) OVERRIDE; |
42 virtual void ReusePictureBuffer(int32_t picture_id) OVERRIDE; | 46 virtual void ReusePictureBuffer(int32_t picture_id) OVERRIDE; |
43 virtual void Flush() OVERRIDE; | 47 virtual void Flush() OVERRIDE; |
44 virtual void Reset() OVERRIDE; | 48 virtual void Reset() OVERRIDE; |
45 virtual void Destroy() OVERRIDE; | 49 virtual void Destroy() OVERRIDE; |
46 virtual bool CanDecodeOnIOThread() OVERRIDE; | 50 virtual bool CanDecodeOnIOThread() OVERRIDE; |
47 | 51 |
48 // Called by VideoToolbox when a frame is decoded. | 52 // Called by OutputThunk() when VideoToolbox finishes decoding a frame. |
49 void Output( | 53 void Output( |
50 int32_t bitstream_id, | 54 int32_t bitstream_id, |
51 OSStatus status, | 55 OSStatus status, |
52 VTDecodeInfoFlags info_flags, | |
53 CVImageBufferRef image_buffer); | 56 CVImageBufferRef image_buffer); |
54 | 57 |
55 private: | 58 private: |
56 // Configure a VideoToolbox decompression session from parameter set NALUs. | 59 struct DecodedFrame { |
| 60 DecodedFrame(int32_t bitstream_id, CVImageBufferRef image_buffer); |
| 61 ~DecodedFrame(); |
| 62 |
| 63 int32_t bitstream_id; |
| 64 base::ScopedCFTypeRef<CVImageBufferRef> image_buffer; |
| 65 }; |
| 66 |
| 67 // Methods for interacting with VideoToolbox. Run on |decoder_thread_|. |
57 void ConfigureDecoder( | 68 void ConfigureDecoder( |
58 const std::vector<const uint8_t*>& nalu_data_ptrs, | 69 const std::vector<const uint8_t*>& nalu_data_ptrs, |
59 const std::vector<size_t>& nalu_data_sizes); | 70 const std::vector<size_t>& nalu_data_sizes); |
60 | |
61 // Decode a frame of bitstream. | |
62 void DecodeTask(const media::BitstreamBuffer); | 71 void DecodeTask(const media::BitstreamBuffer); |
63 | 72 |
| 73 // Methods for interacting with |client_|. Run on |gpu_task_runner_|. |
| 74 void OutputTask(DecodedFrame frame); |
| 75 void SizeChangedTask(gfx::Size coded_size); |
| 76 void SendPictures(); |
| 77 |
| 78 // |
| 79 // GPU thread state. |
| 80 // |
64 CGLContextObj cgl_context_; | 81 CGLContextObj cgl_context_; |
65 media::VideoDecodeAccelerator::Client* client_; | 82 media::VideoDecodeAccelerator::Client* client_; |
66 base::Thread decoder_thread_; | 83 gfx::Size texture_size_; |
67 | 84 |
68 // Decoder configuration (used only on decoder thread). | 85 // Texture IDs of pictures. |
| 86 // TODO(sandersd): A single map of structs holding picture data. |
| 87 std::map<int32_t, uint32_t> texture_ids_; |
| 88 |
| 89 // Pictures ready to be rendered to. |
| 90 std::queue<int32_t> available_picture_ids_; |
| 91 |
| 92 // Decoded frames ready to render. |
| 93 std::queue<DecodedFrame> decoded_frames_; |
| 94 |
| 95 // Image buffers retained while they are bound to pictures. |
| 96 std::map<int32_t, base::ScopedCFTypeRef<CVImageBufferRef>> picture_bindings_; |
| 97 |
| 98 // |
| 99 // Decoder thread state. |
| 100 // |
69 VTDecompressionOutputCallbackRecord callback_; | 101 VTDecompressionOutputCallbackRecord callback_; |
70 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_; | 102 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_; |
71 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_; | 103 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_; |
72 media::H264Parser parser_; | 104 media::H264Parser parser_; |
73 gfx::Size coded_size_; | 105 gfx::Size coded_size_; |
74 | 106 |
75 // Member variables should appear before the WeakPtrFactory, to ensure | 107 // |
76 // that any WeakPtrs to Controller are invalidated before its members | 108 // Unprotected shared state (set up and torn down on GPU thread). |
77 // variable's destructors are executed, rendering them invalid. | 109 // |
| 110 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; |
| 111 |
| 112 // This WeakPtrFactory does not need to be last as its pointers are bound to |
| 113 // the same thread it is destructed on (the GPU thread). |
78 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; | 114 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; |
79 | 115 |
| 116 // Declared last to ensure that all decoder thread tasks complete before any |
| 117 // state is destructed. |
| 118 base::Thread decoder_thread_; |
| 119 |
80 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); | 120 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); |
81 }; | 121 }; |
82 | 122 |
83 } // namespace content | 123 } // namespace content |
84 | 124 |
85 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ | 125 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |