null_audio_sink.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2012 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 MEDIA_FILTERS_NULL_AUDIO_RENDERER_H_ 6#define MEDIA_FILTERS_NULL_AUDIO_RENDERER_H_ 7 8// NullAudioSink effectively uses an extra thread to "throw away" the 9// audio data at a rate resembling normal playback speed. It's just like 10// decoding to /dev/null! 11// 12// NullAudioSink can also be used in situations where the client has no 13// audio device or we haven't written an audio implementation for a particular 14// platform yet. 15 16#include "base/md5.h" 17#include "base/memory/scoped_ptr.h" 18#include "base/threading/thread.h" 19#include "media/base/audio_renderer_sink.h" 20 21namespace media { 22class AudioBus; 23 24class MEDIA_EXPORT NullAudioSink 25 : NON_EXPORTED_BASE(public AudioRendererSink) { 26 public: 27 NullAudioSink(); 28 29 // AudioRendererSink implementation. 30 virtual void Initialize(const AudioParameters& params, 31 RenderCallback* callback) OVERRIDE; 32 virtual void Start() OVERRIDE; 33 virtual void Stop() OVERRIDE; 34 virtual void Pause(bool flush) OVERRIDE; 35 virtual void Play() OVERRIDE; 36 virtual bool SetVolume(double volume) OVERRIDE; 37 38 // Enables audio frame hashing and reinitializes the MD5 context. Must be 39 // called prior to Initialize(). 40 void StartAudioHashForTesting(); 41 42 // Returns the MD5 hash of all audio frames seen since the last reset. 43 std::string GetAudioHashForTesting(); 44 45 protected: 46 virtual ~NullAudioSink(); 47 48 private: 49 // Audio thread task that periodically calls FillBuffer() to consume 50 // audio data. 51 void FillBufferTask(); 52 53 void SetPlaying(bool is_playing); 54 55 // A buffer passed to FillBuffer to advance playback. 56 scoped_ptr<AudioBus> audio_bus_; 57 58 AudioParameters params_; 59 bool initialized_; 60 bool playing_; 61 RenderCallback* callback_; 62 63 // Separate thread used to throw away data. 64 base::Thread thread_; 65 base::Lock lock_; 66 67 // Controls whether or not a running MD5 hash is computed for audio frames. 68 bool hash_audio_for_testing_; 69 scoped_array<base::MD5Context> md5_channel_contexts_; 70 71 DISALLOW_COPY_AND_ASSIGN(NullAudioSink); 72}; 73 74} // namespace media 75 76#endif // MEDIA_FILTERS_NULL_AUDIO_RENDERER_H_ 77