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 ~DecodedFrame(); | |
64 | |
65 int32_t bitstream_id; | |
66 base::ScopedCFTypeRef<CVImageBufferRef> image_buffer; | |
67 }; | |
68 | |
56 // Configure a VideoToolbox decompression session from parameter set NALUs. | 69 // Configure a VideoToolbox decompression session from parameter set NALUs. |
scherkus (not reviewing)
2014/07/17 02:08:26
general comment on comments: comments that are an
sandersd (OOO until July 31)
2014/07/17 20:31:46
Done.
| |
57 void ConfigureDecoder( | 70 void ConfigureDecoder( |
58 const std::vector<const uint8_t*>& nalu_data_ptrs, | 71 const std::vector<const uint8_t*>& nalu_data_ptrs, |
59 const std::vector<size_t>& nalu_data_sizes); | 72 const std::vector<size_t>& nalu_data_sizes); |
60 | 73 |
61 // Decode a frame of bitstream. | 74 // Decode a frame of bitstream. |
62 void DecodeTask(const media::BitstreamBuffer); | 75 void DecodeTask(const media::BitstreamBuffer); |
63 | 76 |
77 // Handle a decoded frame. | |
78 void OutputTask( | |
79 int32_t bitstream_id, | |
80 base::ScopedCFTypeRef<CVImageBufferRef> image_buffer); | |
81 | |
82 // Send decoded frames if possible. | |
83 void SendPictures(); | |
84 | |
85 // | |
86 // GPU thread state. | |
87 // | |
64 CGLContextObj cgl_context_; | 88 CGLContextObj cgl_context_; |
65 media::VideoDecodeAccelerator::Client* client_; | 89 // Texture IDs of pictures. |
66 base::Thread decoder_thread_; | 90 std::map<int32_t, int32_t> texture_ids_; |
91 // Pictures ready to be rendered to. | |
92 std::queue<int32_t> picture_ids_; | |
93 // Decoded frames ready to render. | |
94 std::queue<DecodedFrame> decoded_frames_; | |
95 // Image buffers retained while they are bound to textures. | |
96 std::map<int32_t, base::ScopedCFTypeRef<CVImageBufferRef>> picture_bindings_; | |
67 | 97 |
68 // Decoder configuration (used only on decoder thread). | 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 // Lock-protected shared state. |
77 // variable's destructors are executed, rendering them invalid. | 109 // |
110 base::Lock lock_; | |
111 // Number of frames pending inside VideoToolbox. | |
112 size_t frames_pending_decode_; | |
113 | |
114 // | |
115 // Unprotected shared state (set up and torn down on GPU thread). | |
116 // | |
117 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; | |
118 scoped_ptr<base::WeakPtrFactory<media::VideoDecodeAccelerator::Client>> | |
119 weak_client_factory_; | |
120 | |
121 // Declared second-to-last to prevent any GPU thread tasks from executing once | |
122 // state starts being destroyed. | |
78 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; | 123 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; |
79 | 124 |
125 // Declared last to ensure that all decoder thread tasks complete before any | |
126 // state starts being destroyed. | |
127 base::Thread decoder_thread_; | |
128 | |
80 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); | 129 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); |
81 }; | 130 }; |
82 | 131 |
83 } // namespace content | 132 } // namespace content |
84 | 133 |
85 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ | 134 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |