summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rwxr-xr-x[-rw-r--r--]chrome/common/render_messages.h35
-rw-r--r--chrome/common/render_messages_internal.h25
-rw-r--r--chrome/renderer/DEPS1
-rw-r--r--chrome/renderer/media/audio_renderer_impl.cc18
-rw-r--r--chrome/renderer/media/audio_renderer_impl.h7
-rw-r--r--chrome/renderer/render_view.cc97
-rw-r--r--chrome/renderer/render_view.h35
7 files changed, 218 insertions, 0 deletions
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index e78970e..e2a0aa0 100644..100755
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -1707,6 +1707,41 @@ struct ParamTraits<gfx::NativeView> {
#endif // defined(OS_POSIX)
+template <>
+struct ParamTraits<AudioOutputStream::State> {
+ typedef AudioOutputStream::State param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteInt(p);
+ }
+ static bool Read(const Message* m, void** iter, param_type* p) {
+ int type;
+ if (!m->ReadInt(iter, &type))
+ return false;
+ *p = static_cast<AudioOutputStream::State>(type);
+ return true;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ std::wstring state;
+ switch (p) {
+ case AudioOutputStream::STATE_PAUSED:
+ state = L"AUDIO_STREAM_PAUSED";
+ break;
+ case AudioOutputStream::STATE_STARTED:
+ state = L"AUDIO_STREAM_STARTED";
+ break;
+ case AudioOutputStream::STATE_ERROR:
+ state = L"AUDIO_STREAM_ERROR";
+ break;
+ default:
+ state = L"UNKNOWN";
+ break;
+ }
+
+ LogParam(state, l);
+ }
+};
+
+
} // namespace IPC
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index f02f5cf..8475890 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -498,6 +498,31 @@ IPC_BEGIN_MESSAGES(View)
IPC_MESSAGE_ROUTED1(ViewMsg_PopupNotificationVisiblityChanged,
bool /* Whether it is visible */)
+ // Sent by AudioRendererHost to renderer to request an audio packet.
+ IPC_MESSAGE_ROUTED1(ViewMsg_RequestAudioPacket,
+ int /* stream id */)
+
+ // Tell the renderer process that the audio stream has been created, renderer
+ // process would be given a ShareMemoryHandle that it should write to from
+ // then on.
+ IPC_MESSAGE_ROUTED3(ViewMsg_NotifyAudioStreamCreated,
+ int /* stream id */,
+ base::SharedMemoryHandle /* handle */,
+ int /* length */)
+
+ // Notification message sent from AudioRendererHost to renderer for state
+ // update after the renderer has requested a Create/Start/Close.
+ IPC_MESSAGE_ROUTED3(ViewMsg_NotifyAudioStreamStateChanged,
+ int /* stream id */,
+ AudioOutputStream::State /* new state */,
+ int /* additional information (e.g. platform specific
+ error code*/)
+
+ IPC_MESSAGE_ROUTED3(ViewMsg_NotifyAudioStreamVolume,
+ int /* stream id */,
+ double /* left channel */,
+ double /* right channel */)
+
IPC_END_MESSAGES(View)
diff --git a/chrome/renderer/DEPS b/chrome/renderer/DEPS
index 23643c8d..817eba7 100644
--- a/chrome/renderer/DEPS
+++ b/chrome/renderer/DEPS
@@ -3,6 +3,7 @@ include_rules = [
"+chrome/personalization",
"+chrome/plugin",
"+grit", # For generated headers
+ "+media/audio",
"+media/base", # For HTML5 media rendering.
"+sandbox/src",
"+skia/ext",
diff --git a/chrome/renderer/media/audio_renderer_impl.cc b/chrome/renderer/media/audio_renderer_impl.cc
index 113d700..9dbd392 100644
--- a/chrome/renderer/media/audio_renderer_impl.cc
+++ b/chrome/renderer/media/audio_renderer_impl.cc
@@ -32,3 +32,21 @@ bool AudioRendererImpl::IsMediaFormatSupported(
// TODO(hclam): check the format correct.
return true;
}
+
+void AudioRendererImpl::OnRequestPacket() {
+ // TODO(hclam): implement this.
+}
+
+void AudioRendererImpl::OnCreated(base::SharedMemoryHandle handle,
+ size_t length) {
+ // TODO(hclam): implement this.
+}
+
+void AudioRendererImpl::OnStateChanged(AudioOutputStream::State state,
+ int info) {
+ // TODO(hclam): implement this.
+}
+
+void AudioRendererImpl::OnVolume(double left, double right) {
+ // TODO(hclam): implement this.
+}
diff --git a/chrome/renderer/media/audio_renderer_impl.h b/chrome/renderer/media/audio_renderer_impl.h
index e76bf64..9d6b0b4 100644
--- a/chrome/renderer/media/audio_renderer_impl.h
+++ b/chrome/renderer/media/audio_renderer_impl.h
@@ -5,6 +5,8 @@
#ifndef CHROME_RENDERER_MEDIA_AUDIO_RENDERER_IMPL_H_
#define CHROME_RENDERER_MEDIA_AUDIO_RENDERER_IMPL_H_
+#include "base/shared_memory.h"
+#include "media/audio/audio_output.h"
#include "media/base/factory.h"
#include "media/base/filters.h"
@@ -31,6 +33,11 @@ class AudioRendererImpl : public media::AudioRenderer {
// Answers question from the factory to see if we accept |format|.
static bool IsMediaFormatSupported(const media::MediaFormat* format);
+ void OnRequestPacket();
+ void OnStateChanged(AudioOutputStream::State state, int info);
+ void OnCreated(base::SharedMemoryHandle handle, size_t length);
+ void OnVolume(double left, double right);
+
protected:
virtual ~AudioRendererImpl();
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 10f314d..9528187 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -26,6 +26,7 @@
#include "chrome/renderer/about_handler.h"
#include "chrome/renderer/debug_message_handler.h"
#include "chrome/renderer/localized_error.h"
+#include "chrome/renderer/media/audio_renderer_impl.h"
#include "chrome/renderer/render_process.h"
#include "chrome/renderer/user_script_slave.h"
#include "chrome/renderer/visitedlink_slave.h"
@@ -408,6 +409,11 @@ void RenderView::OnMessageReceived(const IPC::Message& message) {
OnReceivedAutofillSuggestions)
IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisiblityChanged,
OnPopupNotificationVisiblityChanged)
+ IPC_MESSAGE_HANDLER(ViewMsg_RequestAudioPacket, OnRequestAudioPacket)
+ IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamCreated, OnAudioStreamCreated)
+ IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamStateChanged,
+ OnAudioStreamStateChanged)
+ IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamVolume, OnAudioStreamVolume)
// Have the super handle all other messages.
IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
@@ -2864,3 +2870,94 @@ MessageLoop* RenderView::GetMessageLoopForIO() {
return g_render_thread->owner_loop();
return NULL;
}
+
+void RenderView::OnRequestAudioPacket(int stream_id) {
+ AudioRendererImpl* audio_renderer = audio_renderers_.Lookup(stream_id);
+ if (!audio_renderer){
+ NOTREACHED();
+ return;
+ }
+ audio_renderer->OnRequestPacket();
+}
+
+void RenderView::OnAudioStreamCreated(
+ int stream_id, base::SharedMemoryHandle handle, int length) {
+ AudioRendererImpl* audio_renderer = audio_renderers_.Lookup(stream_id);
+ if (!audio_renderer){
+ NOTREACHED();
+ return;
+ }
+ audio_renderer->OnCreated(handle, length);
+}
+
+void RenderView::OnAudioStreamStateChanged(
+ int stream_id, AudioOutputStream::State state, int info) {
+ AudioRendererImpl* audio_renderer = audio_renderers_.Lookup(stream_id);
+ if (!audio_renderer){
+ NOTREACHED();
+ return;
+ }
+ audio_renderer->OnStateChanged(state, info);
+}
+
+void RenderView::OnAudioStreamVolume(int stream_id, double left, double right) {
+ AudioRendererImpl* audio_renderer = audio_renderers_.Lookup(stream_id);
+ if (!audio_renderer){
+ NOTREACHED();
+ return;
+ }
+ audio_renderer->OnVolume(left, right);
+}
+
+int32 RenderView::CreateAudioStream(AudioRendererImpl* audio_renderer,
+ AudioManager::Format format, int channels,
+ int sample_rate, int bits_per_sample,
+ size_t packet_size) {
+ // TODO(hclam): make sure this method is called on render thread.
+ // Loop through the map and make sure there's no renderer already in the map.
+ for (IDMap<AudioRendererImpl>::const_iterator iter = audio_renderers_.begin();
+ iter != audio_renderers_.end(); ++iter) {
+ DCHECK(iter->second != audio_renderer);
+ }
+
+ // Add to map and send the IPC to browser process.
+ int32 stream_id = audio_renderers_.Add(audio_renderer);
+ ViewHostMsg_Audio_CreateStream params;
+ params.format = format;
+ params.channels = channels;
+ params.sample_rate = sample_rate;
+ params.bits_per_sample = bits_per_sample;
+ params.packet_size = packet_size;
+ Send(new ViewHostMsg_CreateAudioStream(routing_id_, stream_id, params));
+ return stream_id;
+}
+
+void RenderView::StartAudioStream(int stream_id) {
+ // TODO(hclam): make sure this method is called on render thread.
+ DCHECK(audio_renderers_.Lookup(stream_id) != NULL);
+ Send(new ViewHostMsg_StartAudioStream(routing_id_, stream_id));
+}
+
+void RenderView::CloseAudioStream(int stream_id) {
+ // TODO(hclam): make sure this method is called on render thread.
+ DCHECK(audio_renderers_.Lookup(stream_id) != NULL);
+ Send(new ViewHostMsg_CloseAudioStream(routing_id_, stream_id));
+}
+
+void RenderView::NotifyAudioPacketReady(int stream_id) {
+ // TODO(hclam): make sure this method is called on render thread.
+ DCHECK(audio_renderers_.Lookup(stream_id) != NULL);
+ Send(new ViewHostMsg_NotifyAudioPacketReady(routing_id_, stream_id));
+}
+
+void RenderView::GetAudioVolume(int stream_id) {
+ // TODO(hclam): make sure this method is called on render thread.
+ DCHECK(audio_renderers_.Lookup(stream_id) != NULL);
+ Send(new ViewHostMsg_GetAudioVolume(routing_id_, stream_id));
+}
+
+void RenderView::SetAudioVolume(int stream_id, double left, double right) {
+ // TODO(hclam): make sure this method is called on render thread.
+ DCHECK(audio_renderers_.Lookup(stream_id) != NULL);
+ Send(new ViewHostMsg_SetAudioVolume(routing_id_, stream_id, left, right));
+}
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index 59e2fad..9ff7e06 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -11,6 +11,8 @@
#include "base/basictypes.h"
#include "base/gfx/point.h"
#include "base/gfx/rect.h"
+#include "base/id_map.h"
+#include "base/shared_memory.h"
#include "base/timer.h"
#include "base/values.h"
#include "build/build_config.h"
@@ -23,6 +25,7 @@
#include "chrome/renderer/external_host_bindings.h"
#include "chrome/renderer/external_js_object.h"
#include "chrome/renderer/render_widget.h"
+#include "media/audio/audio_output.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
#include "webkit/glue/console_message_level.h"
#include "webkit/glue/dom_serializer_delegate.h"
@@ -38,6 +41,7 @@
#pragma warning(disable: 4250)
#endif
+class AudioRendererImpl;
class DictionaryValue;
class DebugMessageHandler;
class FilePath;
@@ -342,6 +346,19 @@ class RenderView : public RenderWidget,
// the renderer, which processes all IPC, to any I/O should be non-blocking.
MessageLoop* GetMessageLoopForIO();
+ // Register the audio renderer and try to create an audio output stream in the
+ // browser process. Always return a stream id. Audio renderer will then
+ // receive state change notification messages.
+ int32 CreateAudioStream(AudioRendererImpl* renderer,
+ AudioManager::Format format, int channels,
+ int sample_rate, int bits_per_sample,
+ size_t packet_size);
+ void StartAudioStream(int stream_id);
+ void CloseAudioStream(int stream_id);
+ void NotifyAudioPacketReady(int stream_id);
+ void GetAudioVolume(int stream_id);
+ void SetAudioVolume(int stream_id, double left, double right);
+
private:
FRIEND_TEST(RenderViewTest, OnLoadAlternateHTMLText);
FRIEND_TEST(RenderViewTest, OnNavStateChanged);
@@ -524,6 +541,21 @@ class RenderView : public RenderWidget,
// grouping, and should form our own grouping.
void OnDisassociateFromPopupCount();
+ // Received when browser process wants more audio packet.
+ void OnRequestAudioPacket(int stream_id);
+
+ // Received when browser process has created an audio output stream for us.
+ void OnAudioStreamCreated(int stream_id, base::SharedMemoryHandle handle,
+ int length);
+
+ // Received when internal state of browser process' audio output device has
+ // changed.
+ void OnAudioStreamStateChanged(int stream_id, AudioOutputStream::State state,
+ int info);
+
+ // Notification of volume property of an audio output stream.
+ void OnAudioStreamVolume(int stream_id, double left, double right);
+
// Switches the frame's CSS media type to "print" and calculate the number of
// printed pages that are to be expected. |frame| will be used to calculate
// the number of expected pages for this frame only.
@@ -752,6 +784,9 @@ class RenderView : public RenderWidget,
// change but is overridden by tests.
int delay_seconds_for_form_state_sync_;
+ // A set of audio renderers registered to use IPC for audio output.
+ IDMap<AudioRendererImpl> audio_renderers_;
+
DISALLOW_COPY_AND_ASSIGN(RenderView);
};