Chromium Code Reviews| 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 // This file contains an implementation of VideoDecoderAccelerator | 5 // This file contains an implementation of VideoDecoderAccelerator |
| 6 // that utilizes the hardware video decoder present on the Exynos SoC. | 6 // that utilizes the hardware video decoder present on the Exynos SoC. |
| 7 | 7 |
| 8 #ifndef CONTENT_COMMON_GPU_MEDIA_EXYNOS_VIDEO_DECODE_ACCELERATOR_H_ | 8 #ifndef CONTENT_COMMON_GPU_MEDIA_EXYNOS_VIDEO_DECODE_ACCELERATOR_H_ |
| 9 #define CONTENT_COMMON_GPU_MEDIA_EXYNOS_VIDEO_DECODE_ACCELERATOR_H_ | 9 #define CONTENT_COMMON_GPU_MEDIA_EXYNOS_VIDEO_DECODE_ACCELERATOR_H_ |
| 10 | 10 |
| 11 #include <list> | 11 #include <list> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
| 15 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 19 #include "content/common/gpu/media/video_decode_accelerator_impl.h" | |
| 19 #include "media/base/video_decoder_config.h" | 20 #include "media/base/video_decoder_config.h" |
| 20 #include "media/video/video_decode_accelerator.h" | |
| 21 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
| 22 #include "ui/gl/gl_bindings.h" | 22 #include "ui/gl/gl_bindings.h" |
| 23 | 23 |
| 24 namespace base { | 24 namespace base { |
| 25 class MessageLoopProxy; | 25 class MessageLoopProxy; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 class H264Parser; | 29 class H264Parser; |
| 30 | 30 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 47 // ServiceDeviceTask(). Almost all state modification is done on this thread. | 47 // ServiceDeviceTask(). Almost all state modification is done on this thread. |
| 48 // * The device_poll_thread_, owned by this class. All it does is epoll() on | 48 // * The device_poll_thread_, owned by this class. All it does is epoll() on |
| 49 // the V4L2 in DevicePollTask() and schedule a ServiceDeviceTask() on the | 49 // the V4L2 in DevicePollTask() and schedule a ServiceDeviceTask() on the |
| 50 // decoder_thread_ when something interesting happens. | 50 // decoder_thread_ when something interesting happens. |
| 51 // TODO(sheu): replace this thread with an TYPE_IO decoder_thread_. | 51 // TODO(sheu): replace this thread with an TYPE_IO decoder_thread_. |
| 52 // | 52 // |
| 53 // Note that this class has no locks! Everything's serviced on the | 53 // Note that this class has no locks! Everything's serviced on the |
| 54 // decoder_thread_, so there are no synchronization issues. | 54 // decoder_thread_, so there are no synchronization issues. |
| 55 // ... well, there are, but it's a matter of getting messages posted in the | 55 // ... well, there are, but it's a matter of getting messages posted in the |
| 56 // right order, not fiddling with locks. | 56 // right order, not fiddling with locks. |
| 57 class CONTENT_EXPORT ExynosVideoDecodeAccelerator : | 57 class CONTENT_EXPORT ExynosVideoDecodeAccelerator |
| 58 public media::VideoDecodeAccelerator { | 58 : public VideoDecodeAcceleratorImpl { |
| 59 public: | 59 public: |
| 60 ExynosVideoDecodeAccelerator( | 60 ExynosVideoDecodeAccelerator( |
| 61 EGLDisplay egl_display, | 61 EGLDisplay egl_display, |
| 62 EGLContext egl_context, | 62 EGLContext egl_context, |
| 63 Client* client, | 63 Client* client, |
| 64 const base::Callback<bool(void)>& make_context_current); | 64 const base::Callback<bool(void)>& make_context_current, |
| 65 const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy); | |
| 65 virtual ~ExynosVideoDecodeAccelerator(); | 66 virtual ~ExynosVideoDecodeAccelerator(); |
| 66 | 67 |
| 67 // media::VideoDecodeAccelerator implementation. | 68 // media::VideoDecodeAccelerator implementation. |
| 68 // Note: Initialize() and Destroy() are synchronous. | 69 // Note: Initialize() and Destroy() are synchronous. |
| 69 virtual bool Initialize(media::VideoCodecProfile profile) OVERRIDE; | 70 virtual bool Initialize(media::VideoCodecProfile profile) OVERRIDE; |
| 70 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; | 71 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; |
| 71 virtual void AssignPictureBuffers( | 72 virtual void AssignPictureBuffers( |
| 72 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; | 73 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; |
| 73 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; | 74 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; |
| 74 virtual void Flush() OVERRIDE; | 75 virtual void Flush() OVERRIDE; |
| 75 virtual void Reset() OVERRIDE; | 76 virtual void Reset() OVERRIDE; |
| 76 virtual void Destroy() OVERRIDE; | 77 virtual void Destroy() OVERRIDE; |
| 77 | 78 |
| 79 // VideoDecodeAcceleratorImpl implementation. | |
| 80 virtual bool CanDecodeOnIOThread() OVERRIDE { return true; } | |
|
piman
2013/08/27 17:14:22
nit: don't inline virtual methods.
wuchengli
2013/08/28 13:18:21
Done.
| |
| 81 | |
| 78 // Do any necessary initialization before the sandbox is enabled. | 82 // Do any necessary initialization before the sandbox is enabled. |
| 79 static void PreSandboxInitialization(); | 83 static void PreSandboxInitialization(); |
| 80 | 84 |
| 81 // Lazily initialize static data after sandbox is enabled. Return false on | 85 // Lazily initialize static data after sandbox is enabled. Return false on |
| 82 // init failure. | 86 // init failure. |
| 83 static bool PostSandboxInitialization(); | 87 static bool PostSandboxInitialization(); |
| 84 | 88 |
| 85 private: | 89 private: |
| 86 // These are rather subjectively tuned. | 90 // These are rather subjectively tuned. |
| 87 enum { | 91 enum { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 int32 picture_id; // picture buffer id as returned to PictureReady(). | 175 int32 picture_id; // picture buffer id as returned to PictureReady(). |
| 172 }; | 176 }; |
| 173 | 177 |
| 174 // | 178 // |
| 175 // Decoding tasks, to be run on decode_thread_. | 179 // Decoding tasks, to be run on decode_thread_. |
| 176 // | 180 // |
| 177 | 181 |
| 178 // Enqueue a BitstreamBuffer to decode. This will enqueue a buffer to the | 182 // Enqueue a BitstreamBuffer to decode. This will enqueue a buffer to the |
| 179 // decoder_input_queue_, then queue a DecodeBufferTask() to actually decode | 183 // decoder_input_queue_, then queue a DecodeBufferTask() to actually decode |
| 180 // the buffer. | 184 // the buffer. |
| 181 void DecodeTask(scoped_ptr<BitstreamBufferRef> bitstream_record); | 185 void DecodeTask(const media::BitstreamBuffer& bitstream_buffer); |
| 182 | 186 |
| 183 // Decode from the buffers queued in decoder_input_queue_. Calls | 187 // Decode from the buffers queued in decoder_input_queue_. Calls |
| 184 // DecodeBufferInitial() or DecodeBufferContinue() as appropriate. | 188 // DecodeBufferInitial() or DecodeBufferContinue() as appropriate. |
| 185 void DecodeBufferTask(); | 189 void DecodeBufferTask(); |
| 186 // Advance to the next fragment that begins a frame. | 190 // Advance to the next fragment that begins a frame. |
| 187 bool AdvanceFrameFragment(const uint8* data, size_t size, size_t* endpos); | 191 bool AdvanceFrameFragment(const uint8* data, size_t size, size_t* endpos); |
| 188 // Schedule another DecodeBufferTask() if we're behind. | 192 // Schedule another DecodeBufferTask() if we're behind. |
| 189 void ScheduleDecodeBufferTaskIfNeeded(); | 193 void ScheduleDecodeBufferTaskIfNeeded(); |
| 190 | 194 |
| 191 // Return true if we should continue to schedule DecodeBufferTask()s after | 195 // Return true if we should continue to schedule DecodeBufferTask()s after |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 // Destroy buffers. | 308 // Destroy buffers. |
| 305 void DestroyMfcInputBuffers(); | 309 void DestroyMfcInputBuffers(); |
| 306 void DestroyMfcOutputBuffers(); | 310 void DestroyMfcOutputBuffers(); |
| 307 void DestroyGscInputBuffers(); | 311 void DestroyGscInputBuffers(); |
| 308 void DestroyGscOutputBuffers(); | 312 void DestroyGscOutputBuffers(); |
| 309 void ResolutionChangeDestroyBuffers(); | 313 void ResolutionChangeDestroyBuffers(); |
| 310 | 314 |
| 311 // Our original calling message loop for the child thread. | 315 // Our original calling message loop for the child thread. |
| 312 scoped_refptr<base::MessageLoopProxy> child_message_loop_proxy_; | 316 scoped_refptr<base::MessageLoopProxy> child_message_loop_proxy_; |
| 313 | 317 |
| 318 // Message loop of the IO thread. | |
| 319 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | |
| 320 | |
| 314 // WeakPtr<> pointing to |this| for use in posting tasks from the decoder or | 321 // WeakPtr<> pointing to |this| for use in posting tasks from the decoder or |
| 315 // device worker threads back to the child thread. Because the worker threads | 322 // device worker threads back to the child thread. Because the worker threads |
| 316 // are members of this class, any task running on those threads is guaranteed | 323 // are members of this class, any task running on those threads is guaranteed |
| 317 // that this object is still alive. As a result, tasks posted from the child | 324 // that this object is still alive. As a result, tasks posted from the child |
| 318 // thread to the decoder or device thread should use base::Unretained(this), | 325 // thread to the decoder or device thread should use base::Unretained(this), |
| 319 // and tasks posted the other way should use |weak_this_|. | 326 // and tasks posted the other way should use |weak_this_|. |
| 320 base::WeakPtr<ExynosVideoDecodeAccelerator> weak_this_; | 327 base::WeakPtr<ExynosVideoDecodeAccelerator> weak_this_; |
| 321 | 328 |
| 322 // To expose client callbacks from VideoDecodeAccelerator. | 329 // To expose client callbacks from VideoDecodeAccelerator. |
| 323 // NOTE: all calls to these objects *MUST* be executed on | 330 // NOTE: all calls to these objects *MUST* be executed on |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 | 457 |
| 451 // The codec we'll be decoding for. | 458 // The codec we'll be decoding for. |
| 452 media::VideoCodecProfile video_profile_; | 459 media::VideoCodecProfile video_profile_; |
| 453 | 460 |
| 454 DISALLOW_COPY_AND_ASSIGN(ExynosVideoDecodeAccelerator); | 461 DISALLOW_COPY_AND_ASSIGN(ExynosVideoDecodeAccelerator); |
| 455 }; | 462 }; |
| 456 | 463 |
| 457 } // namespace content | 464 } // namespace content |
| 458 | 465 |
| 459 #endif // CONTENT_COMMON_GPU_MEDIA_EXYNOS_VIDEO_DECODE_ACCELERATOR_H_ | 466 #endif // CONTENT_COMMON_GPU_MEDIA_EXYNOS_VIDEO_DECODE_ACCELERATOR_H_ |
| OLD | NEW |