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 15 matching lines...) Expand all Loading... | |
38 Client* client) OVERRIDE; | 43 Client* client) OVERRIDE; |
39 virtual void Decode(const media::BitstreamBuffer& bitstream) OVERRIDE; | 44 virtual void Decode(const media::BitstreamBuffer& bitstream) OVERRIDE; |
40 virtual void AssignPictureBuffers( | 45 virtual void AssignPictureBuffers( |
41 const std::vector<media::PictureBuffer>& pictures) OVERRIDE; | 46 const std::vector<media::PictureBuffer>& pictures) OVERRIDE; |
42 virtual void ReusePictureBuffer(int32_t picture_id) OVERRIDE; | 47 virtual void ReusePictureBuffer(int32_t picture_id) OVERRIDE; |
43 virtual void Flush() OVERRIDE; | 48 virtual void Flush() OVERRIDE; |
44 virtual void Reset() OVERRIDE; | 49 virtual void Reset() OVERRIDE; |
45 virtual void Destroy() OVERRIDE; | 50 virtual void Destroy() OVERRIDE; |
46 virtual bool CanDecodeOnIOThread() OVERRIDE; | 51 virtual bool CanDecodeOnIOThread() OVERRIDE; |
47 | 52 |
48 // Called by VideoToolbox when a frame is decoded. | 53 // Called by OutputThunk when VideoToolbox finishes decoding a frame. |
scherkus (not reviewing)
2014/07/17 21:17:26
nit: we have a convention of adding a "()" suffix
scherkus (not reviewing)
2014/07/17 23:32:51
FYI not done
sandersd (OOO until July 31)
2014/07/18 01:05:15
Done.
| |
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, | |
53 CVImageBufferRef image_buffer); | 57 CVImageBufferRef image_buffer); |
54 | 58 |
55 private: | 59 private: |
56 // Configure a VideoToolbox decompression session from parameter set NALUs. | 60 struct DecodedFrame { |
61 DecodedFrame(uint32_t bitstream_id, CVImageBufferRef image_buffer); | |
62 ~DecodedFrame(); | |
63 | |
64 int32_t bitstream_id; | |
65 base::ScopedCFTypeRef<CVImageBufferRef> image_buffer; | |
66 }; | |
67 | |
68 // Methods for interacting with VideoToolbox. Run on |decoded_thread_|. | |
scherkus (not reviewing)
2014/07/17 21:17:26
typo: decoded -> decoder
scherkus (not reviewing)
2014/07/17 23:32:51
FYI not done
sandersd (OOO until July 31)
2014/07/18 01:05:15
Done.
| |
57 void ConfigureDecoder( | 69 void ConfigureDecoder( |
58 const std::vector<const uint8_t*>& nalu_data_ptrs, | 70 const std::vector<const uint8_t*>& nalu_data_ptrs, |
59 const std::vector<size_t>& nalu_data_sizes); | 71 const std::vector<size_t>& nalu_data_sizes); |
60 | |
61 // Decode a frame of bitstream. | |
62 void DecodeTask(const media::BitstreamBuffer); | 72 void DecodeTask(const media::BitstreamBuffer); |
63 | 73 |
74 // Methods for interacting with |client_|. Run on |gpu_task_runner_|. | |
75 void OutputTask(DecodedFrame frame); | |
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 // Texture IDs of pictures. |
84 std::map<int32_t, int32_t> texture_ids_; | |
85 // Pictures ready to be rendered to. | |
86 std::queue<int32_t> picture_ids_; | |
87 // Decoded frames ready to render. | |
88 std::queue<DecodedFrame> decoded_frames_; | |
89 // Image buffers retained while they are bound to textures. | |
90 std::map<int32_t, base::ScopedCFTypeRef<CVImageBufferRef>> picture_bindings_; | |
scherkus (not reviewing)
2014/07/17 21:17:26
interesting fact: apparently because we compile wi
sandersd (OOO until July 31)
2014/07/18 01:05:15
Acknowledged.
| |
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 // Unprotected shared state (set up and torn down on GPU thread). |
77 // variable's destructors are executed, rendering them invalid. | 103 // |
104 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; | |
105 scoped_ptr<base::WeakPtrFactory<media::VideoDecodeAccelerator::Client>> | |
106 weak_client_factory_; | |
107 | |
108 // Declared second-to-last to prevent any GPU thread tasks from executing once | |
109 // state starts being destroyed. | |
scherkus (not reviewing)
2014/07/17 21:17:26
the old comment was more accurate
the situation y
scherkus (not reviewing)
2014/07/17 23:32:51
FYI not done
sandersd (OOO until July 31)
2014/07/18 01:05:15
Ah yes, now that this is correctly used from only
| |
78 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; | 110 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; |
79 | 111 |
112 // Declared last to ensure that all decoder thread tasks complete before any | |
113 // state starts being destroyed. | |
114 base::Thread decoder_thread_; | |
115 | |
80 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); | 116 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); |
81 }; | 117 }; |
82 | 118 |
83 } // namespace content | 119 } // namespace content |
84 | 120 |
85 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ | 121 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |