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 PPAPI_PROXY_MEDIA_STREAM_AUDIO_TRACK_RESOURCE_H_
6#define PPAPI_PROXY_MEDIA_STREAM_AUDIO_TRACK_RESOURCE_H_
7
8#include <map>
9#include <string>
10
11#include "base/memory/ref_counted.h"
12#include "ppapi/proxy/media_stream_track_resource_base.h"
13#include "ppapi/proxy/ppapi_proxy_export.h"
14#include "ppapi/thunk/ppb_media_stream_audio_track_api.h"
15
16namespace ppapi {
17namespace proxy {
18
19class AudioBufferResource;
20
21class PPAPI_PROXY_EXPORT MediaStreamAudioTrackResource
22    : public MediaStreamTrackResourceBase,
23      public thunk::PPB_MediaStreamAudioTrack_API {
24 public:
25  MediaStreamAudioTrackResource(Connection connection,
26                                PP_Instance instance,
27                                int pending_renderer_id,
28                                const std::string& id);
29
30  virtual ~MediaStreamAudioTrackResource();
31
32  // Resource overrides:
33  virtual thunk::PPB_MediaStreamAudioTrack_API*
34  AsPPB_MediaStreamAudioTrack_API() OVERRIDE;
35
36  // PPB_MediaStreamAudioTrack_API overrides:
37  virtual PP_Var GetId() OVERRIDE;
38  virtual PP_Bool HasEnded() OVERRIDE;
39  virtual int32_t Configure(const int32_t attrib_list[],
40                            scoped_refptr<TrackedCallback> callback) OVERRIDE;
41  virtual int32_t GetAttrib(PP_MediaStreamAudioTrack_Attrib attrib,
42                            int32_t* value) OVERRIDE;
43  virtual int32_t GetBuffer(
44      PP_Resource* buffer,
45      scoped_refptr<TrackedCallback> callback) OVERRIDE;
46  virtual int32_t RecycleBuffer(PP_Resource buffer) OVERRIDE;
47  virtual void Close() OVERRIDE;
48
49  // MediaStreamBufferManager::Delegate overrides:
50  virtual void OnNewBufferEnqueued() OVERRIDE;
51
52 private:
53  PP_Resource GetAudioBuffer();
54
55  void ReleaseBuffers();
56
57  // IPC message handlers.
58  void OnPluginMsgConfigureReply(const ResourceMessageReplyParams& params);
59
60  // Allocated buffer resources by |GetBuffer()|.
61  typedef std::map<PP_Resource, scoped_refptr<AudioBufferResource> > BufferMap;
62  BufferMap buffers_;
63
64  PP_Resource* get_buffer_output_;
65
66  scoped_refptr<TrackedCallback> configure_callback_;
67
68  scoped_refptr<TrackedCallback> get_buffer_callback_;
69
70  DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrackResource);
71};
72
73}  // namespace proxy
74}  // namespace ppapi
75
76#endif  // PPAPI_PROXY_MEDIA_STREAM_AUDIO_TRACK_RESOURCE_H_
77