1// Copyright 2014 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_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_TRACK_HOST_BASE_H_ 6#define CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_TRACK_HOST_BASE_H_ 7 8#include "base/compiler_specific.h" 9#include "content/common/content_export.h" 10#include "ppapi/host/resource_host.h" 11#include "ppapi/shared_impl/media_stream_buffer_manager.h" 12 13namespace content { 14 15class RendererPpapiHost; 16 17class PepperMediaStreamTrackHostBase 18 : public ppapi::host::ResourceHost, 19 public ppapi::MediaStreamBufferManager::Delegate { 20 protected: 21 PepperMediaStreamTrackHostBase(RendererPpapiHost* host, 22 PP_Instance instance, 23 PP_Resource resource); 24 virtual ~PepperMediaStreamTrackHostBase(); 25 26 enum TrackType { 27 kRead, 28 kWrite 29 }; 30 bool InitBuffers(int32_t number_of_buffers, 31 int32_t buffer_size, 32 TrackType track_type); 33 34 ppapi::MediaStreamBufferManager* buffer_manager() { return &buffer_manager_; } 35 36 // Sends a buffer index to the corresponding MediaStreamTrackResourceBase 37 // via an IPC message. The resource adds the buffer index into its 38 // |buffer_manager_| for reading or writing. 39 // Also see |MediaStreamBufferManager|. 40 void SendEnqueueBufferMessageToPlugin(int32_t index); 41 42 // Sends a set of buffer indices to the corresponding 43 // MediaStreamTrackResourceBase via an IPC message. 44 // The resource adds the buffer indices into its 45 // |frame_buffer_| for reading or writing. Also see |MediaStreamFrameBuffer|. 46 void SendEnqueueBuffersMessageToPlugin(const std::vector<int32_t>& indices); 47 48 // ResourceMessageHandler overrides: 49 virtual int32_t OnResourceMessageReceived( 50 const IPC::Message& msg, 51 ppapi::host::HostMessageContext* context) OVERRIDE; 52 53 // Message handlers: 54 virtual int32_t OnHostMsgEnqueueBuffer( 55 ppapi::host::HostMessageContext* context, int32_t index); 56 57 private: 58 // Subclasses must implement this method to clean up when the track is closed. 59 virtual void OnClose() = 0; 60 61 // Message handlers: 62 int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context); 63 64 RendererPpapiHost* host_; 65 66 ppapi::MediaStreamBufferManager buffer_manager_; 67 68 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamTrackHostBase); 69}; 70 71} // namespace content 72 73#endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_TRACK_HOST_BASE_H_ 74