| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_MAC_VIDEO_DECODE_ACCELERATOR_H_ | 5 #ifndef CONTENT_COMMON_GPU_MEDIA_MAC_VIDEO_DECODE_ACCELERATOR_H_ |
| 6 #define CONTENT_COMMON_GPU_MEDIA_MAC_VIDEO_DECODE_ACCELERATOR_H_ | 6 #define CONTENT_COMMON_GPU_MEDIA_MAC_VIDEO_DECODE_ACCELERATOR_H_ |
| 7 | 7 |
| 8 #include <CoreVideo/CoreVideo.h> | 8 #include <CoreVideo/CoreVideo.h> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <list> | 10 #include <list> |
| 11 | 11 |
| 12 #include "base/mac/scoped_cftyperef.h" | 12 #include "base/mac/scoped_cftyperef.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 #include "content/common/gpu/media/avc_config_record_builder.h" |
| 17 #include "content/common/gpu/media/h264_parser.h" |
| 16 #include "media/video/video_decode_accelerator.h" | 18 #include "media/video/video_decode_accelerator.h" |
| 17 | 19 |
| 18 namespace base { | 20 namespace base { |
| 19 class RefCountedBytes; | 21 class RefCountedBytes; |
| 20 } | 22 } |
| 21 namespace gfx { | 23 namespace gfx { |
| 22 class GLContext; | 24 class GLContext; |
| 23 class VideoDecodeAccelerationSupport; | 25 class VideoDecodeAccelerationSupport; |
| 24 } | 26 } |
| 25 | 27 |
| 26 class GpuCommandBufferStub; | 28 class GpuCommandBufferStub; |
| 27 | 29 |
| 28 class CONTENT_EXPORT MacVideoDecodeAccelerator | 30 class CONTENT_EXPORT MacVideoDecodeAccelerator |
| 29 : public media::VideoDecodeAccelerator, | 31 : public media::VideoDecodeAccelerator, |
| 30 public base::NonThreadSafe { | 32 public base::NonThreadSafe { |
| 31 public: | 33 public: |
| 32 // Does not take ownership of |client| which must outlive |*this|. | 34 // Does not take ownership of |client| which must outlive |*this|. |
| 33 MacVideoDecodeAccelerator(media::VideoDecodeAccelerator::Client* client); | 35 MacVideoDecodeAccelerator(media::VideoDecodeAccelerator::Client* client); |
| 34 | 36 |
| 35 // Set the OpenGL context to use. | 37 // Set the OpenGL context to use. |
| 36 void SetCGLContext(CGLContextObj cgl_context); | 38 void SetCGLContext(CGLContextObj cgl_context); |
| 37 | 39 |
| 38 // Set extra data required to initialize the H.264 video decoder. | |
| 39 // TODO(sail): Move this into Initialize. | |
| 40 bool SetConfigInfo(uint32_t frame_width, | |
| 41 uint32_t frame_height, | |
| 42 const std::vector<uint8_t>& avc_data); | |
| 43 | |
| 44 // media::VideoDecodeAccelerator implementation. | 40 // media::VideoDecodeAccelerator implementation. |
| 45 virtual bool Initialize(media::VideoCodecProfile profile) OVERRIDE; | 41 virtual bool Initialize(media::VideoCodecProfile profile) OVERRIDE; |
| 46 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; | 42 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; |
| 47 virtual void AssignPictureBuffers( | 43 virtual void AssignPictureBuffers( |
| 48 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; | 44 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; |
| 49 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; | 45 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; |
| 50 virtual void Flush() OVERRIDE; | 46 virtual void Flush() OVERRIDE; |
| 51 virtual void Reset() OVERRIDE; | 47 virtual void Reset() OVERRIDE; |
| 52 virtual void Destroy() OVERRIDE; | 48 virtual void Destroy() OVERRIDE; |
| 53 | 49 |
| 54 private: | 50 private: |
| 55 virtual ~MacVideoDecodeAccelerator(); | 51 virtual ~MacVideoDecodeAccelerator(); |
| 56 | 52 |
| 57 // Callback for a completed frame. | 53 // Callback for a completed frame. |
| 58 void OnFrameReady(int32 bitstream_buffer_id, | 54 void OnFrameReady(int32 bitstream_buffer_id, |
| 59 scoped_refptr<base::RefCountedBytes> bytes, | 55 scoped_refptr<base::RefCountedBytes> bytes, |
| 60 CVImageBufferRef image, | 56 CVImageBufferRef image, |
| 61 int status); | 57 int status); |
| 62 | 58 |
| 63 // Sends available decoded frames to the client. | 59 // Sends available decoded frames to the client. |
| 64 void SendImages(); | 60 void SendImages(); |
| 65 | 61 |
| 66 // Stop the component when any error is detected. | 62 // Stop the component when any error is detected. |
| 67 void StopOnError(media::VideoDecodeAccelerator::Error error); | 63 void StopOnError(media::VideoDecodeAccelerator::Error error); |
| 68 | 64 |
| 65 // Create the decoder. |
| 66 bool CreateDecoder(const std::vector<uint8_t>& extra_data); |
| 67 |
| 68 // Send the given NALU to the decoder. |
| 69 void DecodeNALU(const content::H264NALU& nalu, |
| 70 int32 bitstream_buffer_id); |
| 71 |
| 69 // Calls the client's initialize completed callback. | 72 // Calls the client's initialize completed callback. |
| 70 void NotifyInitializeDone(); | 73 void NotifyInitializeDone(); |
| 71 | 74 |
| 72 // Requests pictures from the client. | 75 // Requests pictures from the client. |
| 73 void RequestPictures(); | 76 void RequestPictures(); |
| 74 | 77 |
| 75 // Calls the client's flush completed callback. | 78 // Calls the client's flush completed callback. |
| 76 void NotifyFlushDone(); | 79 void NotifyFlushDone(); |
| 77 | 80 |
| 78 // Calls the client's reset completed callback. | 81 // Calls the client's reset completed callback. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 105 DecodedImageInfo(); | 108 DecodedImageInfo(); |
| 106 ~DecodedImageInfo(); | 109 ~DecodedImageInfo(); |
| 107 base::mac::ScopedCFTypeRef<CVImageBufferRef> image; | 110 base::mac::ScopedCFTypeRef<CVImageBufferRef> image; |
| 108 int32 bitstream_buffer_id; | 111 int32 bitstream_buffer_id; |
| 109 }; | 112 }; |
| 110 std::list<DecodedImageInfo> decoded_images_; | 113 std::list<DecodedImageInfo> decoded_images_; |
| 111 | 114 |
| 112 // The context to use to perform OpenGL operations. | 115 // The context to use to perform OpenGL operations. |
| 113 CGLContextObj cgl_context_; | 116 CGLContextObj cgl_context_; |
| 114 | 117 |
| 115 // The number of bytes used to store the frame buffer size. | 118 // Flag to check if AVC decoder configuration record has been built. |
| 116 size_t nalu_len_field_size_; | 119 bool did_build_config_record_; |
| 117 | 120 |
| 118 // Size of a video frame. | 121 // Parser for the H264 stream. |
| 119 gfx::Size frame_size_; | 122 content::H264Parser h264_parser_; |
| 120 | 123 |
| 121 // Flag to check if pictures have been requested from the client. | 124 // Utility to build the AVC configuration record. |
| 122 bool did_request_pictures_; | 125 content::AVCConfigRecordBuilder config_record_builder_; |
| 123 }; | 126 }; |
| 124 | 127 |
| 125 #endif // CONTENT_COMMON_GPU_MEDIA_VIDEO_DECODE_ACCELERATOR_MAC_H_ | 128 #endif // CONTENT_COMMON_GPU_MEDIA_VIDEO_DECODE_ACCELERATOR_MAC_H_ |
| OLD | NEW |