OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef UI_GFX_VIDEO_DECODE_ACCELERATION_SUPPORT_MAC_H_ | |
6 #define UI_GFX_VIDEO_DECODE_ACCELERATION_SUPPORT_MAC_H_ | |
7 | |
8 #include <CoreFoundation/CoreFoundation.h> | |
9 #include <CoreVideo/CoreVideo.h> | |
10 #include <map> | |
11 | |
12 #include <VideoDecodeAcceleration/VDADecoder.h> | |
13 | |
14 #include "base/basictypes.h" | |
15 #include "base/callback.h" | |
16 #include "base/gtest_prod_util.h" | |
17 #include "base/memory/ref_counted.h" | |
18 #include "base/message_loop/message_loop_proxy.h" | |
19 #include "ui/base/ui_export.h" | |
20 | |
21 class FrameCallbackUtil; | |
22 class VideoDecodeAccelerationSupportTest; | |
23 | |
24 namespace gfx { | |
25 | |
26 // This Mac OS X-specific class provides dynamically linked access to | |
27 // VideoDecodeAcceleration.framework, which is only available on 10.6 and later. | |
28 class UI_EXPORT VideoDecodeAccelerationSupport | |
29 : public base::RefCountedThreadSafe<VideoDecodeAccelerationSupport> { | |
30 public: | |
31 enum Status { | |
32 SUCCESS = 0, | |
33 LOAD_FRAMEWORK_ERROR, | |
34 HARDWARE_NOT_SUPPORTED_ERROR, | |
35 OTHER_ERROR, | |
36 }; | |
37 | |
38 typedef base::Callback<void(CVImageBufferRef, int status)> FrameReadyCallback; | |
39 | |
40 VideoDecodeAccelerationSupport(); | |
41 | |
42 // Calls the create function. | |
43 Status Create(int width, int height, | |
44 int pixel_format, | |
45 const void* avc_bytes, size_t avc_size); | |
46 | |
47 // Calls the decode function with the given data. |cb| is invoked once the | |
48 // frame has been decoded. | |
49 Status Decode(const void* bytes, size_t size, const FrameReadyCallback& cb); | |
50 | |
51 // Calls the flush function. If |emit_frames| is true then all pending frames | |
52 // are synchronoulsy decoded, otherwise the pending frames are discarded. | |
53 Status Flush(bool emit_frames); | |
54 | |
55 // Calls the destory function. | |
56 Status Destroy(); | |
57 | |
58 private: | |
59 friend class base::RefCountedThreadSafe<VideoDecodeAccelerationSupport>; | |
60 FRIEND_TEST_ALL_PREFIXES(VideoDecodeAccelerationSupportTest, Callback); | |
61 | |
62 ~VideoDecodeAccelerationSupport(); | |
63 | |
64 static void OnFrameReadyCallback(void* callback_data, | |
65 CFDictionaryRef frame_info, | |
66 OSStatus status, | |
67 uint32_t flags, | |
68 CVImageBufferRef image_buffer); | |
69 void OnFrameReady(CVImageBufferRef image_buffer, | |
70 OSStatus status, | |
71 int frame_id); | |
72 | |
73 // Reference to the VDA decoder. | |
74 VDADecoder decoder_; | |
75 | |
76 // A monotonically increasing number. This is used to assign a unique ID for | |
77 // decode frame request. | |
78 int frame_id_count_; | |
79 | |
80 // Maps a unique ID to the callback given to the decode function. | |
81 std::map<int, FrameReadyCallback> frame_ready_callbacks_; | |
82 | |
83 // A reference to the message loop that this object was created on. This is | |
84 // used to invoke the frame ready callback on the correct thread. | |
85 scoped_refptr<base::MessageLoopProxy> loop_; | |
86 | |
87 DISALLOW_COPY_AND_ASSIGN(VideoDecodeAccelerationSupport); | |
88 }; | |
89 | |
90 } // namespace gfx | |
91 | |
92 #endif // UI_GFX_VIDEO_DECODE_ACCELERATION_SUPPORT_MAC_H_ | |
OLD | NEW |