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