Home | History | Annotate | Download | only in media
      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_GPU_VIDEO_DECODE_ACCELERATOR_H_
      6 #define CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/compiler_specific.h"
     11 #include "base/memory/ref_counted.h"
     12 #include "base/memory/shared_memory.h"
     13 #include "content/common/gpu/gpu_command_buffer_stub.h"
     14 #include "ipc/ipc_listener.h"
     15 #include "ipc/ipc_sender.h"
     16 #include "media/video/video_decode_accelerator.h"
     17 
     18 namespace content {
     19 
     20 class GpuVideoDecodeAccelerator
     21     : public IPC::Listener,
     22       public IPC::Sender,
     23       public media::VideoDecodeAccelerator::Client,
     24       public GpuCommandBufferStub::DestructionObserver {
     25  public:
     26   // Each of the arguments to the constructor must outlive this object.
     27   // |stub->decoder()| will be made current around any operation that touches
     28   // the underlying VDA so that it can make GL calls safely.
     29   GpuVideoDecodeAccelerator(int32 host_route_id, GpuCommandBufferStub* stub);
     30   virtual ~GpuVideoDecodeAccelerator();
     31 
     32   // IPC::Listener implementation.
     33   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
     34 
     35   // media::VideoDecodeAccelerator::Client implementation.
     36   virtual void ProvidePictureBuffers(uint32 requested_num_of_buffers,
     37                                      const gfx::Size& dimensions,
     38                                      uint32 texture_target) OVERRIDE;
     39   virtual void DismissPictureBuffer(int32 picture_buffer_id) OVERRIDE;
     40   virtual void PictureReady(const media::Picture& picture) OVERRIDE;
     41   virtual void NotifyInitializeDone() OVERRIDE;
     42   virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE;
     43   virtual void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id) OVERRIDE;
     44   virtual void NotifyFlushDone() OVERRIDE;
     45   virtual void NotifyResetDone() OVERRIDE;
     46 
     47   // GpuCommandBufferStub::DestructionObserver implementation.
     48   virtual void OnWillDestroyStub() OVERRIDE;
     49 
     50   // Function to delegate sending to actual sender.
     51   virtual bool Send(IPC::Message* message) OVERRIDE;
     52 
     53   // Initialize the accelerator with the given profile and send the
     54   // |init_done_msg| when done.
     55   // The renderer process handle is valid as long as we have a channel between
     56   // GPU process and the renderer.
     57   void Initialize(const media::VideoCodecProfile profile,
     58                   IPC::Message* init_done_msg);
     59 
     60  private:
     61   // Handlers for IPC messages.
     62   void OnDecode(base::SharedMemoryHandle handle, int32 id, uint32 size);
     63   void OnAssignPictureBuffers(
     64       const std::vector<int32>& buffer_ids,
     65       const std::vector<uint32>& texture_ids,
     66       const std::vector<gfx::Size>& sizes);
     67   void OnReusePictureBuffer(
     68       int32 picture_buffer_id);
     69   void OnFlush();
     70   void OnReset();
     71   void OnDestroy();
     72 
     73   // Message to Send() when initialization is done.  Is only non-NULL during
     74   // initialization and is owned by the IPC channel underlying the
     75   // GpuCommandBufferStub.
     76   IPC::Message* init_done_msg_;
     77 
     78   // Route ID to communicate with the host.
     79   int32 host_route_id_;
     80 
     81   // Unowned pointer to the underlying GpuCommandBufferStub.
     82   GpuCommandBufferStub* stub_;
     83 
     84   // The underlying VideoDecodeAccelerator.
     85   scoped_ptr<media::VideoDecodeAccelerator> video_decode_accelerator_;
     86 
     87   // Callback for making the relevant context current for GL calls.
     88   // Returns false if failed.
     89   base::Callback<bool(void)> make_context_current_;
     90 
     91   // The texture target as requested by ProvidePictureBuffers().
     92   uint32 texture_target_;
     93 
     94   DISALLOW_IMPLICIT_CONSTRUCTORS(GpuVideoDecodeAccelerator);
     95 };
     96 
     97 }  // namespace content
     98 
     99 #endif  // CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_H_
    100