Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(459)

Side by Side Diff: content/common/gpu/media/vt_video_decode_accelerator.h

Issue 397883002: Implement actually decoding frames in VTVideoDecodeAccelerator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix race on coded_size_. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
Pawel Osciak 2014/07/18 01:22:13 I don't see any usage of scoped_ptr in this class.
sandersd (OOO until July 31) 2014/07/18 21:50:15 Done.
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"
Pawel Osciak 2014/07/18 01:22:12 Unused?
sandersd (OOO until July 31) 2014/07/18 21:50:15 Done.
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
23 28
24 namespace content { 29 namespace content {
25 30
26 // VideoToolbox.framework implementation of the VideoDecodeAccelerator 31 // VideoToolbox.framework implementation of the VideoDecodeAccelerator
27 // interface for Mac OS X (currently limited to 10.9+). 32 // interface for Mac OS X (currently limited to 10.9+).
28 class VTVideoDecodeAccelerator 33 class VTVideoDecodeAccelerator
29 : public media::VideoDecodeAccelerator, 34 : public media::VideoDecodeAccelerator,
30 public base::NonThreadSafe { 35 public base::NonThreadSafe {
31 public: 36 public:
32 explicit VTVideoDecodeAccelerator(CGLContextObj cgl_context); 37 explicit VTVideoDecodeAccelerator(CGLContextObj cgl_context);
33 virtual ~VTVideoDecodeAccelerator(); 38 virtual ~VTVideoDecodeAccelerator();
34 39
35 // VideoDecodeAccelerator implementation. 40 // VideoDecodeAccelerator implementation.
36 virtual bool Initialize( 41 virtual bool Initialize(
37 media::VideoCodecProfile profile, 42 media::VideoCodecProfile profile,
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;
Pawel Osciak 2014/07/18 01:22:13 Need to include stdint.h for int32_t.
sandersd (OOO until July 31) 2014/07/18 21:50:14 Done.
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.
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_|.
57 void ConfigureDecoder( 69 void ConfigureDecoder(
Pawel Osciak 2014/07/18 01:22:13 s/ConfigureDecoder/ConfigureDecoderTask/ ?
sandersd (OOO until July 31) 2014/07/18 21:50:14 ConfigureDecoder is a utility method that is only
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 SizeChangedTask(gfx::Size coded_size);
77 void SendPictures();
Pawel Osciak 2014/07/18 01:22:12 Task?
sandersd (OOO until July 31) 2014/07/18 21:50:14 This one I'm not sure of. It's usually called as a
78
79 //
80 // GPU thread state.
81 //
64 CGLContextObj cgl_context_; 82 CGLContextObj cgl_context_;
65 media::VideoDecodeAccelerator::Client* client_; 83 media::VideoDecodeAccelerator::Client* client_;
66 base::Thread decoder_thread_; 84 gfx::Size texture_size_;
Pawel Osciak 2014/07/18 01:22:12 Shouldn't this be the same as coded_size_ ?
sandersd (OOO until July 31) 2014/07/18 21:50:15 It's nearly the same, but one is owned by the deco
85 // Texture IDs of pictures.
86 std::map<int32_t, int32_t> texture_ids_;
Pawel Osciak 2014/07/18 01:22:12 texture ids are uint32
sandersd (OOO until July 31) 2014/07/18 21:50:14 Done.
87 // Pictures ready to be rendered to.
88 std::queue<int32_t> picture_ids_;
Pawel Osciak 2014/07/18 01:22:13 s/picture_ids_/available_picture_ids_/ ?
sandersd (OOO until July 31) 2014/07/18 21:50:14 Done.
89 // Decoded frames ready to render.
90 std::queue<DecodedFrame> decoded_frames_;
91 // Image buffers retained while they are bound to textures.
92 std::map<int32_t, base::ScopedCFTypeRef<CVImageBufferRef>> picture_bindings_;
Pawel Osciak 2014/07/18 01:22:12 Is the first parameter a texture id? -> uint32. A
sandersd (OOO until July 31) 2014/07/18 21:50:15 It's a picture ID. This is a reasonable idea (it'
67 93
68 // Decoder configuration (used only on decoder thread). 94 //
95 // Decoder thread state.
96 //
69 VTDecompressionOutputCallbackRecord callback_; 97 VTDecompressionOutputCallbackRecord callback_;
70 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_; 98 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_;
71 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_; 99 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_;
72 media::H264Parser parser_; 100 media::H264Parser parser_;
73 gfx::Size coded_size_; 101 gfx::Size coded_size_;
74 102
75 // Member variables should appear before the WeakPtrFactory, to ensure 103 //
76 // that any WeakPtrs to Controller are invalidated before its members 104 // Unprotected shared state (set up and torn down on GPU thread).
Pawel Osciak 2014/07/18 01:22:13 What does "unprotected" mean?
sandersd (OOO until July 31) 2014/07/18 21:50:14 It means there is no lock (there will be lock-prot
77 // variable's destructors are executed, rendering them invalid. 105 //
106 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_;
107
108 // Declared second-to-last to prevent any GPU thread tasks from executing once
109 // state starts being destroyed.
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698