15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_TRACK_HOST_BASE_H_
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_TRACK_HOST_BASE_H_
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/compiler_specific.h"
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/common/content_export.h"
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ppapi/host/resource_host.h"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ppapi/shared_impl/media_stream_buffer_manager.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace content {
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class RendererPpapiHost;
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class PepperMediaStreamTrackHostBase
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : public ppapi::host::ResourceHost,
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      public ppapi::MediaStreamBufferManager::Delegate {
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) protected:
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  PepperMediaStreamTrackHostBase(RendererPpapiHost* host,
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                 PP_Instance instance,
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                 PP_Resource resource);
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~PepperMediaStreamTrackHostBase();
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
26010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  enum TrackType {
27010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    kRead,
28010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    kWrite
29010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  };
30010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  bool InitBuffers(int32_t number_of_buffers,
31010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                   int32_t buffer_size,
32010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                   TrackType track_type);
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ppapi::MediaStreamBufferManager* buffer_manager() { return &buffer_manager_; }
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Sends a buffer index to the corresponding MediaStreamTrackResourceBase
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // via an IPC message. The resource adds the buffer index into its
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // |buffer_manager_| for reading or writing.
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Also see |MediaStreamBufferManager|.
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void SendEnqueueBufferMessageToPlugin(int32_t index);
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
42010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Sends a set of buffer indices to the corresponding
43010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // MediaStreamTrackResourceBase via an IPC message.
44010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // The resource adds the buffer indices into its
45010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // |frame_buffer_| for reading or writing. Also see |MediaStreamFrameBuffer|.
46010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void SendEnqueueBuffersMessageToPlugin(const std::vector<int32_t>& indices);
47010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // ResourceMessageHandler overrides:
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual int32_t OnResourceMessageReceived(
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const IPC::Message& msg,
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ppapi::host::HostMessageContext* context) OVERRIDE;
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
53010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Message handlers:
54010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual int32_t OnHostMsgEnqueueBuffer(
55010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      ppapi::host::HostMessageContext* context, int32_t index);
56010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) private:
58a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Subclasses must implement this method to clean up when the track is closed.
59a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void OnClose() = 0;
60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Message handlers:
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context);
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  RendererPpapiHost* host_;
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ppapi::MediaStreamBufferManager buffer_manager_;
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamTrackHostBase);
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // namespace content
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif  // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_TRACK_HOST_BASE_H_
74