Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / renderer / pepper / pepper_media_stream_track_host_base.h
blobddfac9cb7d91a429983096224a9a783e7838176b
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.
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_TRACK_HOST_BASE_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_TRACK_HOST_BASE_H_
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"
13 namespace content {
15 class RendererPpapiHost;
17 class 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 ~PepperMediaStreamTrackHostBase() override;
26 enum TrackType {
27 kRead,
28 kWrite
30 bool InitBuffers(int32_t number_of_buffers,
31 int32_t buffer_size,
32 TrackType track_type);
34 ppapi::MediaStreamBufferManager* buffer_manager() { return &buffer_manager_; }
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);
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);
48 // ResourceMessageHandler overrides:
49 int32_t OnResourceMessageReceived(
50 const IPC::Message& msg,
51 ppapi::host::HostMessageContext* context) override;
53 // Message handlers:
54 virtual int32_t OnHostMsgEnqueueBuffer(
55 ppapi::host::HostMessageContext* context, int32_t index);
57 private:
58 // Subclasses must implement this method to clean up when the track is closed.
59 virtual void OnClose() = 0;
61 // Message handlers:
62 int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context);
64 RendererPpapiHost* host_;
66 ppapi::MediaStreamBufferManager buffer_manager_;
68 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamTrackHostBase);
71 } // namespace content
73 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_TRACK_HOST_BASE_H_