1 // Copyright 2013 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_BROWSER_MEDIA_ANDROID_BROWSER_DEMUXER_ANDROID_H_
6 #define CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_DEMUXER_ANDROID_H_
10 #include "base/id_map.h"
11 #include "content/public/browser/browser_message_filter.h"
12 #include "media/base/android/demuxer_android.h"
16 // Represents the browser process half of an IPC-based demuxer proxy.
17 // It vends out media::DemuxerAndroid instances that are registered with an
18 // end point in the renderer process.
20 // Refer to RendererDemuxerAndroid for the renderer process half.
21 class CONTENT_EXPORT BrowserDemuxerAndroid
: public BrowserMessageFilter
{
23 BrowserDemuxerAndroid();
25 // BrowserMessageFilter overrides.
26 base::TaskRunner
* OverrideTaskRunnerForMessage(
27 const IPC::Message
& message
) override
;
29 bool OnMessageReceived(const IPC::Message
& message
) override
;
31 // Returns an uninitialized demuxer implementation associated with
32 // |demuxer_client_id|, which can be used to communicate with the real demuxer
33 // in the renderer process.
34 scoped_ptr
<media::DemuxerAndroid
> CreateDemuxer(int demuxer_client_id
);
37 friend class base::RefCountedThreadSafe
<BrowserDemuxerAndroid
>;
38 ~BrowserDemuxerAndroid() override
;
43 // Called by internal demuxer implementations to add/remove a client
45 void AddDemuxerClient(int demuxer_client_id
,
46 media::DemuxerAndroidClient
* client
);
47 void RemoveDemuxerClient(int demuxer_client_id
);
49 // IPC message handlers.
50 void OnDemuxerReady(int demuxer_client_id
,
51 const media::DemuxerConfigs
& configs
);
52 void OnReadFromDemuxerAck(int demuxer_client_id
,
53 const media::DemuxerData
& data
);
54 void OnDemuxerSeekDone(int demuxer_client_id
,
55 const base::TimeDelta
& actual_browser_seek_time
);
56 void OnDurationChanged(int demuxer_client_id
,
57 const base::TimeDelta
& duration
);
59 IDMap
<media::DemuxerAndroidClient
> demuxer_clients_
;
61 // When the demuxer client is created on UI thread but demuxer
62 // messages arrive on Media thread their relative order is undefined.
63 // Use |pending_configs_| map to keep the upcoming configurations
64 // until the client is created.
65 typedef std::map
<int, media::DemuxerConfigs
> ConfigsPerClient
;
66 ConfigsPerClient pending_configs_
;
68 base::SingleThreadTaskRunner
* task_runner_
;
70 DISALLOW_COPY_AND_ASSIGN(BrowserDemuxerAndroid
);
73 } // namespace content
75 #endif // CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_DEMUXER_ANDROID_H_