summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authornfullagar@google.com <nfullagar@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-25 00:29:25 +0000
committernfullagar@google.com <nfullagar@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-25 00:29:25 +0000
commit06417271819fc46ae45a76ed0d2e2bb18b5dad01 (patch)
treea13c12ada2e5c4875f3a7de54a8464785744b3ba /ppapi
parentf68e75ab0e1215c0f3446efc0586a4be02798878 (diff)
downloadchromium_src-06417271819fc46ae45a76ed0d2e2bb18b5dad01.zip
chromium_src-06417271819fc46ae45a76ed0d2e2bb18b5dad01.tar.gz
chromium_src-06417271819fc46ae45a76ed0d2e2bb18b5dad01.tar.bz2
changes for proxy audio
- includes Darin's changes to move StreamCreated() to main thread - callback for delivering handles to proxy - changes to trusted interface BUG=none TEST=chrome/src/ppapi/examples/audio/audio.cc Review URL: http://codereview.chromium.org/5202002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67354 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/c/dev/ppb_audio_trusted_dev.h40
-rw-r--r--ppapi/examples/audio/audio.cc22
2 files changed, 38 insertions, 24 deletions
diff --git a/ppapi/c/dev/ppb_audio_trusted_dev.h b/ppapi/c/dev/ppb_audio_trusted_dev.h
index acb883f..4c250b6 100644
--- a/ppapi/c/dev/ppb_audio_trusted_dev.h
+++ b/ppapi/c/dev/ppb_audio_trusted_dev.h
@@ -5,23 +5,37 @@
#ifndef PPAPI_C_DEV_PPB_AUDIO_TRUSTED_DEV_H_
#define PPAPI_C_DEV_PPB_AUDIO_TRUSTED_DEV_H_
+#include "ppapi/c/pp_completion_callback.h"
+#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_resource.h"
-#define PPB_AUDIO_TRUSTED_DEV_INTERFACE "PPB_AudioTrusted(Dev);0.1"
+#define PPB_AUDIO_TRUSTED_DEV_INTERFACE "PPB_AudioTrusted(Dev);0.2"
-// This interface is used to get access to the audio buffer and a socket on
-// which the client can block until the audio is ready to accept more data.
-// This interface should be used by NaCl to implement the Audio interface.
+// This interface is to be used by proxy implementations. All
+// functions should be called from the main thread only. The
+// resource returned is an Audio resource; most of the PPB_Audio_Dev
+// interface is also usable on this resource.
struct PPB_AudioTrusted_Dev {
- // Returns a Buffer object that has the audio buffer.
- PP_Resource (*GetBuffer)(PP_Resource audio);
-
- // Returns a select()-able/Wait()-able OS-specific descriptor. The browser
- // will put a byte on the socket each time the buffer is ready to be filled.
- // The plugin can then implement its own audio thread using select()/poll() to
- // block until the browser is ready to receive data.
- int (*GetOSDescriptor)(PP_Resource audio);
+ // Returns an audio resource.
+ PP_Resource (*CreateTrusted)(PP_Instance instance);
+
+ // Opens a paused audio interface, used by trusted side of proxy.
+ // Returns PP_ERROR_WOULD_BLOCK on success, and invokes
+ // the |create_callback| asynchronously to complete.
+ // As this function should always be invoked from the main thread,
+ // do not use the blocking variant of PP_CompletionCallback.
+ int32_t (*Open)(PP_Resource audio, PP_Resource config,
+ struct PP_CompletionCallback create_callback);
+
+ // Get the sync socket. Use once Open has completed.
+ // Returns PP_OK on success.
+ int32_t (*GetSyncSocket)(PP_Resource audio, int* sync_socket);
+
+ // Get the shared memory interface. Use once Open has completed.
+ // Returns PP_OK on success.
+ int32_t (*GetSharedMemory)(PP_Resource audio,
+ int* shm_handle,
+ int32_t* shm_size);
};
#endif // PPAPI_C_DEV_PPB_AUDIO_TRUSTED_DEV_H_
-
diff --git a/ppapi/examples/audio/audio.cc b/ppapi/examples/audio/audio.cc
index 8f80ba4..fcef2b1 100644
--- a/ppapi/examples/audio/audio.cc
+++ b/ppapi/examples/audio/audio.cc
@@ -6,6 +6,7 @@
#include <limits>
#include "ppapi/cpp/dev/audio_dev.h"
+#include "ppapi/cpp/dev/audio_config_dev.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
@@ -17,6 +18,7 @@ const double frequency_r = 1000;
// This sample frequency is guaranteed to work.
const PP_AudioSampleRate_Dev sample_frequency = PP_AUDIOSAMPLERATE_44100;
const uint32_t sample_count = 4096;
+uint32_t obtained_sample_count = 0;
class MyInstance : public pp::Instance {
public:
@@ -26,16 +28,16 @@ class MyInstance : public pp::Instance {
}
virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
- audio_ = pp::Audio_Dev(
- *this, pp::AudioConfig_Dev(sample_frequency, sample_count),
- SineWaveCallback, this);
+ pp::AudioConfig_Dev config;
+ obtained_sample_count = pp::AudioConfig_Dev::RecommendSampleFrameCount(
+ sample_count);
+ config = pp::AudioConfig_Dev(sample_frequency, obtained_sample_count);
+ audio_ = pp::Audio_Dev(*this, config, SineWaveCallback, this);
return audio_.StartPlayback();
}
private:
- static void SineWaveCallback(void* samples,
- size_t buffer_size_in_bytes,
- void* thiz) {
+ static void SineWaveCallback(void* samples, size_t num_bytes, void* thiz) {
const double th_l = 2 * 3.141592653589 * frequency_l / sample_frequency;
const double th_r = 2 * 3.141592653589 * frequency_r / sample_frequency;
@@ -43,12 +45,10 @@ class MyInstance : public pp::Instance {
size_t t = reinterpret_cast<MyInstance*>(thiz)->audio_time_;
uint16_t* buf = reinterpret_cast<uint16_t*>(samples);
- for (size_t buffer_index = 0u;
- buffer_index < buffer_size_in_bytes;
- buffer_index += 2) {
- *buf++ = static_cast<uint16_t>(std::sin(th_l * t)
+ for (size_t sample = 0; sample < obtained_sample_count; ++sample) {
+ *buf++ = static_cast<uint16_t>(sin(th_l * t)
* std::numeric_limits<uint16_t>::max());
- *buf++ = static_cast<uint16_t>(std::sin(th_r * t++)
+ *buf++ = static_cast<uint16_t>(sin(th_r * t++)
* std::numeric_limits<uint16_t>::max());
}
reinterpret_cast<MyInstance*>(thiz)->audio_time_ = t;