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. 4 5 #ifndef CONTENT_RENDERER_MEDIA_ANDROID_RENDERER_DEMUXER_ANDROID_H_ 6 #define CONTENT_RENDERER_MEDIA_ANDROID_RENDERER_DEMUXER_ANDROID_H_ 7 8 #include "base/atomic_sequence_num.h" 9 #include "base/id_map.h" 10 #include "ipc/ipc_channel_proxy.h" 11 #include "media/base/android/demuxer_stream_player_params.h" 12 13 namespace content { 14 15 class MediaSourceDelegate; 16 class ThreadSafeSender; 17 18 // Represents the renderer process half of an IPC-based implementation of 19 // media::DemuxerAndroid. 20 // 21 // Refer to BrowserDemuxerAndroid for the browser process half. 22 class RendererDemuxerAndroid : public IPC::ChannelProxy::MessageFilter { 23 public: 24 RendererDemuxerAndroid(); 25 26 // Returns the next available demuxer client ID for use in IPC messages. 27 // 28 // Safe to call on any thread. 29 int GetNextDemuxerClientID(); 30 31 // Associates |delegate| with |demuxer_client_id| for handling incoming IPC 32 // messages. 33 // 34 // Must be called on media thread. 35 void AddDelegate(int demuxer_client_id, MediaSourceDelegate* delegate); 36 37 // Removes the association created by AddDelegate(). 38 // 39 // Must be called on media thread. 40 void RemoveDelegate(int demuxer_client_id); 41 42 // IPC::ChannelProxy::MessageFilter overrides. 43 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 44 45 // media::DemuxerAndroidClient "implementation". 46 // 47 // TODO(scherkus): Consider having RendererDemuxerAndroid actually implement 48 // media::DemuxerAndroidClient and MediaSourceDelegate actually implement 49 // media::DemuxerAndroid. 50 void DemuxerReady(int demuxer_client_id, 51 const media::DemuxerConfigs& configs); 52 void ReadFromDemuxerAck(int demuxer_client_id, 53 const media::DemuxerData& data); 54 void DemuxerSeekDone(int demuxer_client_id, 55 const base::TimeDelta& actual_browser_seek_time); 56 void DurationChanged(int demuxer_client_id, const base::TimeDelta& duration); 57 58 protected: 59 friend class base::RefCountedThreadSafe<RendererDemuxerAndroid>; 60 virtual ~RendererDemuxerAndroid(); 61 62 private: 63 void DispatchMessage(const IPC::Message& message); 64 void OnReadFromDemuxer(int demuxer_client_id, 65 media::DemuxerStream::Type type); 66 void OnDemuxerSeekRequest(int demuxer_client_id, 67 const base::TimeDelta& time_to_seek, 68 bool is_browser_seek); 69 void OnMediaConfigRequest(int demuxer_client_id); 70 71 base::AtomicSequenceNumber next_demuxer_client_id_; 72 73 IDMap<MediaSourceDelegate> delegates_; 74 scoped_refptr<ThreadSafeSender> thread_safe_sender_; 75 scoped_refptr<base::MessageLoopProxy> media_message_loop_; 76 77 DISALLOW_COPY_AND_ASSIGN(RendererDemuxerAndroid); 78 }; 79 80 } // namespace content 81 82 #endif // CONTENT_RENDERER_MEDIA_ANDROID_RENDERER_DEMUXER_ANDROID_H_ 83