| 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 CONTENT_COMMON_GPU_MEDIA_MAC_VIDEO_DECODE_ACCELERATOR_H_ | |
| 6 #define CONTENT_COMMON_GPU_MEDIA_MAC_VIDEO_DECODE_ACCELERATOR_H_ | |
| 7 | |
| 8 #include <CoreVideo/CoreVideo.h> | |
| 9 #include <map> | |
| 10 #include <list> | |
| 11 | |
| 12 #include "base/mac/scoped_cftyperef.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/threading/non_thread_safe.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" | |
| 18 #include "media/video/video_decode_accelerator.h" | |
| 19 | |
| 20 namespace base { | |
| 21 class RefCountedBytes; | |
| 22 } | |
| 23 namespace gfx { | |
| 24 class GLContext; | |
| 25 class VideoDecodeAccelerationSupport; | |
| 26 } | |
| 27 | |
| 28 namespace content { | |
| 29 | |
| 30 class GpuCommandBufferStub; | |
| 31 | |
| 32 class CONTENT_EXPORT MacVideoDecodeAccelerator | |
| 33 : public media::VideoDecodeAccelerator, | |
| 34 public base::NonThreadSafe { | |
| 35 public: | |
| 36 // Does not take ownership of |client| which must outlive |*this|. | |
| 37 MacVideoDecodeAccelerator(CGLContextObj cgl_context, | |
| 38 media::VideoDecodeAccelerator::Client* client); | |
| 39 virtual ~MacVideoDecodeAccelerator(); | |
| 40 | |
| 41 // media::VideoDecodeAccelerator implementation. | |
| 42 virtual bool Initialize(media::VideoCodecProfile profile) OVERRIDE; | |
| 43 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; | |
| 44 virtual void AssignPictureBuffers( | |
| 45 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; | |
| 46 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; | |
| 47 virtual void Flush() OVERRIDE; | |
| 48 virtual void Reset() OVERRIDE; | |
| 49 virtual void Destroy() OVERRIDE; | |
| 50 | |
| 51 private: | |
| 52 | |
| 53 // Callback for a completed frame. | |
| 54 void OnFrameReady(int32 bitstream_buffer_id, | |
| 55 scoped_refptr<base::RefCountedBytes> bytes, | |
| 56 CVImageBufferRef image, | |
| 57 int status); | |
| 58 | |
| 59 // Sends available decoded frames to the client. | |
| 60 void SendImages(); | |
| 61 | |
| 62 // Stop the component when any error is detected. | |
| 63 void StopOnError(media::VideoDecodeAccelerator::Error error); | |
| 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 H264NALU& nalu, int32 bitstream_buffer_id); | |
| 70 | |
| 71 // Calls the client's initialize completed callback. | |
| 72 void NotifyInitializeDone(); | |
| 73 | |
| 74 // Requests pictures from the client. | |
| 75 void RequestPictures(); | |
| 76 | |
| 77 // Calls the client's flush completed callback. | |
| 78 void NotifyFlushDone(); | |
| 79 | |
| 80 // Calls the client's reset completed callback. | |
| 81 void NotifyResetDone(); | |
| 82 | |
| 83 // Notifies the client that the input buffer identifed by |input_buffer_id| | |
| 84 // has been processed. | |
| 85 void NotifyInputBufferRead(int input_buffer_id); | |
| 86 | |
| 87 // Helper for Destroy(), doing all the actual work except for deleting self. | |
| 88 void Cleanup(); | |
| 89 | |
| 90 // To expose client callbacks from VideoDecodeAccelerator. | |
| 91 Client* client_; | |
| 92 // C++ wrapper around the Mac VDA API. | |
| 93 scoped_refptr<gfx::VideoDecodeAccelerationSupport> vda_support_; | |
| 94 // Picture buffers that are available for use by the decoder to draw decoded | |
| 95 // video frames on. | |
| 96 std::list<media::PictureBuffer> available_pictures_; | |
| 97 | |
| 98 // Maps ids to picture buffers that are in use by the client. | |
| 99 struct UsedPictureInfo { | |
| 100 UsedPictureInfo(const media::PictureBuffer& pic, | |
| 101 const base::mac::ScopedCFTypeRef<CVImageBufferRef>& image); | |
| 102 ~UsedPictureInfo(); | |
| 103 const media::PictureBuffer picture_buffer; | |
| 104 const base::mac::ScopedCFTypeRef<CVImageBufferRef> image; | |
| 105 }; | |
| 106 std::map<int32, UsedPictureInfo> used_pictures_; | |
| 107 | |
| 108 // List of decoded images waiting to be sent to the client. | |
| 109 struct DecodedImageInfo { | |
| 110 DecodedImageInfo(); | |
| 111 ~DecodedImageInfo(); | |
| 112 base::mac::ScopedCFTypeRef<CVImageBufferRef> image; | |
| 113 int32 bitstream_buffer_id; | |
| 114 }; | |
| 115 std::list<DecodedImageInfo> decoded_images_; | |
| 116 | |
| 117 // The context to use to perform OpenGL operations. | |
| 118 CGLContextObj cgl_context_; | |
| 119 | |
| 120 // Flag to check if AVC decoder configuration record has been built. | |
| 121 bool did_build_config_record_; | |
| 122 | |
| 123 // Parser for the H264 stream. | |
| 124 H264Parser h264_parser_; | |
| 125 | |
| 126 // Utility to build the AVC configuration record. | |
| 127 AVCConfigRecordBuilder config_record_builder_; | |
| 128 | |
| 129 // Maps a bitstream ID to the number of NALUs that are being decoded for | |
| 130 // that bitstream. This is used to ensure that NotifyEndOfBitstreamBuffer() | |
| 131 // is called after all NALUs contained in a bitstream have been decoded. | |
| 132 std::map<int32, int> bitstream_nalu_count_; | |
| 133 }; | |
| 134 | |
| 135 } // namespace content | |
| 136 | |
| 137 #endif // CONTENT_COMMON_GPU_MEDIA_VIDEO_DECODE_ACCELERATOR_MAC_H_ | |
| OLD | NEW |