0

[ppapi] Remove PPB_AudioEncoder API

- UMA shows this interface has no usage. This is a Dev API at 0.1.

Change-Id: I98aef1dcaf38c9203030526bbdf4e4e51b0e9497
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1574487
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Raymes Khoury <raymes@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814695}
This commit is contained in:
Bill Budge
2020-10-07 16:07:21 +00:00
committed by Commit Bot
parent b30ac1ef17
commit f7d8dd23bb
36 changed files with 2 additions and 2121 deletions

@ -29,7 +29,6 @@
#include "ppapi/c/ppb_audio.h"
#include "ppapi/c/ppb_audio_buffer.h"
#include "ppapi/c/ppb_audio_config.h"
#include "ppapi/c/ppb_audio_encoder.h"
#include "ppapi/c/ppb_console.h"
#include "ppapi/c/ppb_core.h"
#include "ppapi/c/ppb_file_io.h"

@ -1960,11 +1960,6 @@ IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
RUN_AUDIO_CONFIG_SUBTESTS;
}
// Flaky on Windows https://crbug.com/1059468#c18
#if !defined(OS_WIN) || !defined(ARCH_CPU_32_BITS)
TEST_PPAPI_NACL(AudioEncoder)
#endif
// PPB_Audio tests.
#define RUN_AUDIO_SUBTESTS \
RunTestViaHTTP( \

@ -470,8 +470,6 @@ target(link_target_type, "renderer") {
"pepper/message_channel.h",
"pepper/pepper_audio_controller.cc",
"pepper/pepper_audio_controller.h",
"pepper/pepper_audio_encoder_host.cc",
"pepper/pepper_audio_encoder_host.h",
"pepper/pepper_audio_input_host.cc",
"pepper/pepper_audio_input_host.h",
"pepper/pepper_audio_output_host.cc",

@ -14,7 +14,6 @@
#include "content/common/content_switches_internal.h"
#include "content/public/common/content_client.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/renderer/pepper/pepper_audio_encoder_host.h"
#include "content/renderer/pepper/pepper_audio_input_host.h"
#include "content/renderer/pepper/pepper_audio_output_host.h"
#include "content/renderer/pepper/pepper_camera_device_host.h"
@ -156,9 +155,6 @@ ContentRendererPepperHostFactory::CreateResourceHost(
// Dev interfaces.
if (GetPermissions().HasPermission(ppapi::PERMISSION_DEV)) {
switch (message.type()) {
case PpapiHostMsg_AudioEncoder_Create::ID:
return std::make_unique<PepperAudioEncoderHost>(host_, instance,
resource);
case PpapiHostMsg_AudioInput_Create::ID:
return std::make_unique<PepperAudioInputHost>(host_, instance,
resource);

@ -62,7 +62,6 @@
#include "ppapi/c/ppb_audio.h"
#include "ppapi/c/ppb_audio_buffer.h"
#include "ppapi/c/ppb_audio_config.h"
#include "ppapi/c/ppb_audio_encoder.h"
#include "ppapi/c/ppb_console.h"
#include "ppapi/c/ppb_core.h"
#include "ppapi/c/ppb_file_io.h"

@ -64,10 +64,6 @@ PP_Resource ResourceCreationImpl::CreateAudioTrusted(PP_Instance instance) {
return (new PPB_Audio_Impl(instance))->GetReference();
}
PP_Resource ResourceCreationImpl::CreateAudioEncoder(PP_Instance instance) {
return 0; // Not supported in-process.
}
PP_Resource ResourceCreationImpl::CreateAudioInput(PP_Instance instance) {
return 0; // Not supported in-process.
}

@ -33,7 +33,6 @@ class ResourceCreationImpl : public ppapi::thunk::ResourceCreationAPI {
PP_Resource config_id,
PPB_Audio_Callback audio_callback,
void* user_data) override;
PP_Resource CreateAudioEncoder(PP_Instance instance) override;
PP_Resource CreateAudioTrusted(PP_Instance instance) override;
PP_Resource CreateAudioConfig(PP_Instance instance,
PP_AudioSampleRate sample_rate,

@ -21,7 +21,6 @@
'pp_array_output.h',
'ppb_audio_buffer.h',
'ppb_audio_config.h',
'ppb_audio_encoder.h',
'ppb_audio.h',
'ppb_console.h',
'ppb_core.h',

@ -17,7 +17,6 @@
'audio.cc',
'audio_buffer.cc',
'audio_config.cc',
'audio_encoder.cc',
'core.cc',
'directory_entry.cc',
'file_io.cc',
@ -89,7 +88,6 @@
'array_output.h',
'audio_buffer.h',
'audio_config.h',
'audio_encoder.h',
'audio.h',
'completion_callback.h',
'core.h',

@ -32,8 +32,6 @@ test_common_source_files = [
"tests/test_audio.h",
"tests/test_audio_config.cc",
"tests/test_audio_config.h",
"tests/test_audio_encoder.cc",
"tests/test_audio_encoder.h",
"tests/test_case.cc",
"tests/test_case.h",
"tests/test_console.cc",

@ -23,14 +23,6 @@ enum PP_VideoProfile {
PP_VIDEOPROFILE_MAX = PP_VIDEOPROFILE_VP9_ANY
};
/**
* Audio profiles.
*/
enum PP_AudioProfile {
PP_AUDIOPROFILE_OPUS = 0,
PP_AUDIOPROFILE_MAX = PP_AUDIOPROFILE_OPUS
};
/**
* Hardware acceleration options.
*/
@ -187,37 +179,6 @@ struct PP_VideoProfileDescription_0_1 {
PP_HardwareAcceleration acceleration;
};
/**
* Supported audio profile information. See the PPB_AudioEncoder function
* GetSupportedProfiles() for more details.
*/
struct PP_AudioProfileDescription {
/**
* The codec profile.
*/
PP_AudioProfile profile;
/**
* Maximum number of channels that can be encoded.
*/
uint32_t max_channels;
/**
* Sample size.
*/
uint32_t sample_size;
/**
* Sampling rate that can be encoded
*/
uint32_t sample_rate;
/**
* Whether the profile is hardware accelerated.
*/
PP_Bool hardware_accelerated;
};
/**
* Struct describing a bitstream buffer.
*/

@ -1,209 +0,0 @@
/* Copyright 2015 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/**
* This file defines the <code>PPB_AudioEncoder</code> interface.
*/
[generate_thunk]
label Chrome {
[channel=dev] M47 = 0.1
};
/**
* Audio encoder interface.
*
* Typical usage:
* - Call Create() to create a new audio encoder resource.
* - Call GetSupportedProfiles() to determine which codecs and profiles are
* available.
* - Call Initialize() to initialize the encoder for a supported profile.
* - Call GetBuffer() to get an empty buffer and fill it in, or get an audio
* buffer from another resource, e.g. <code>PPB_MediaStreamAudioTrack</code>.
* - Call Encode() to push the audio buffer to the encoder. If an external
* buffer is pushed, wait for completion to recycle the buffer.
* - Call GetBitstreamBuffer() continuously (waiting for each previous call to
* complete) to pull encoded buffers from the encoder.
* - Call RecycleBitstreamBuffer() after consuming the data in the bitstream
* buffer.
* - To destroy the encoder, the plugin should release all of its references to
* it. Any pending callbacks will abort before the encoder is destroyed.
*
* Available audio codecs vary by platform.
* All: opus.
*/
interface PPB_AudioEncoder {
/**
* Creates a new audio encoder resource.
*
* @param[in] instance A <code>PP_Instance</code> identifying the instance
* with the audio encoder.
*
* @return A <code>PP_Resource</code> corresponding to an audio encoder if
* successful or 0 otherwise.
*/
PP_Resource Create([in] PP_Instance instance);
/**
* Determines if the given resource is an audio encoder.
*
* @param[in] resource A <code>PP_Resource</code> identifying a resource.
*
* @return <code>PP_TRUE</code> if the resource is a
* <code>PPB_AudioEncoder</code>, <code>PP_FALSE</code> if the resource is
* invalid or some other type.
*/
PP_Bool IsAudioEncoder([in] PP_Resource resource);
/**
* Gets an array of supported audio encoder profiles.
* These can be used to choose a profile before calling Initialize().
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
* @param[in] output A <code>PP_ArrayOutput</code> to receive the supported
* <code>PP_AudioProfileDescription</code> structs.
* @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
* completion.
*
* @return If >= 0, the number of supported profiles returned, otherwise an
* error code from <code>pp_errors.h</code>.
*/
int32_t GetSupportedProfiles([in] PP_Resource audio_encoder,
[in] PP_ArrayOutput output,
[in] PP_CompletionCallback callback);
/**
* Initializes an audio encoder resource. The plugin should call Initialize()
* successfully before calling any of the functions below.
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
* @param[in] channels The number of audio channels to encode.
* @param[in] input_sampling_rate The sampling rate of the input audio buffer.
* @param[in] input_sample_size The sample size of the input audio buffer.
* @param[in] output_profile A <code>PP_AudioProfile</code> specifying the
* codec profile of the encoded output stream.
* @param[in] initial_bitrate The initial bitrate for the encoder.
* @param[in] acceleration A <code>PP_HardwareAcceleration</code> specifying
* whether to use a hardware accelerated or a software implementation.
* @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
* completion.
*
* @return An int32_t containing an error code from <code>pp_errors.h</code>.
* Returns PP_ERROR_NOTSUPPORTED if audio encoding is not available, or the
* requested codec profile is not supported.
*/
int32_t Initialize([in] PP_Resource audio_encoder,
[in] uint32_t channels,
[in] PP_AudioBuffer_SampleRate input_sample_rate,
[in] PP_AudioBuffer_SampleSize input_sample_size,
[in] PP_AudioProfile output_profile,
[in] uint32_t initial_bitrate,
[in] PP_HardwareAcceleration acceleration,
[in] PP_CompletionCallback callback);
/**
* Gets the number of audio samples per channel that audio buffers must
* contain in order to be processed by the encoder. This will be the number of
* samples per channels contained in buffers returned by GetBuffer().
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
* @return An int32_t containing the number of samples required, or an error
* code from <code>pp_errors.h</code>.
* Returns PP_ERROR_FAILED if Initialize() has not successfully completed.
*/
int32_t GetNumberOfSamples([in] PP_Resource audio_encoder);
/**
* Gets a blank audio buffer (with metadata given by the Initialize()
* call) which can be filled with audio data and passed to the encoder.
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
* @param[out] audio_buffer A blank <code>PPB_AudioBuffer</code> resource.
* @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
* completion.
*
* @return An int32_t containing an error code from <code>pp_errors.h</code>.
* Returns PP_ERROR_FAILED if Initialize() has not successfully completed.
*/
int32_t GetBuffer([in] PP_Resource audio_encoder,
[out] PP_Resource audio_buffer,
[in] PP_CompletionCallback callback);
/**
* Encodes an audio buffer.
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
* @param[in] audio_buffer The <code>PPB_AudioBuffer</code> to be encoded.
* @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
* completion. Plugins that pass <code>PPB_AudioBuffer</code> resources owned
* by other resources should wait for completion before reusing them.
*
* @return An int32_t containing an error code from <code>pp_errors.h</code>.
* Returns PP_ERROR_FAILED if Initialize() has not successfully completed.
*/
int32_t Encode([in] PP_Resource audio_encoder,
[in] PP_Resource audio_buffer,
[in] PP_CompletionCallback callback);
/**
* Gets the next encoded bitstream buffer from the encoder.
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
* @param[out] bitstream_buffer A <code>PP_BitstreamBuffer</code> containing
* encoded audio data.
* @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
* completion. The plugin can call GetBitstreamBuffer from the callback in
* order to continuously "pull" bitstream buffers from the encoder.
*
* @return An int32_t containing an error code from <code>pp_errors.h</code>.
* Returns PP_ERROR_FAILED if Initialize() has not successfully completed.
* Returns PP_ERROR_INPROGRESS if a prior call to GetBitstreamBuffer() has
* not completed.
*/
int32_t GetBitstreamBuffer([in] PP_Resource audio_encoder,
[out] PP_AudioBitstreamBuffer bitstream_buffer,
[in] PP_CompletionCallback callback);
/**
* Recycles a bitstream buffer back to the encoder.
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
* @param[in] bitstream_buffer A <code>PP_BitstreamBuffer</code> that is no
* longer needed by the plugin.
*/
void RecycleBitstreamBuffer([in] PP_Resource audio_encoder,
[in] PP_AudioBitstreamBuffer bitstream_buffer);
/**
* Requests a change to the encoding bitrate. This is only a request,
* fulfilled on a best-effort basis.
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
* @param[in] bitrate The requested new bitrate, in bits per second.
*/
void RequestBitrateChange([in] PP_Resource audio_encoder,
[in] uint32_t bitrate);
/**
* Closes the audio encoder, and cancels any pending encodes. Any pending
* callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> . It is
* not valid to call any encoder functions after a call to this method.
* <strong>Note:</strong> Destroying the audio encoder closes it implicitly,
* so you are not required to call Close().
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
*/
void Close([in] PP_Resource audio_encoder);
};

@ -29,7 +29,6 @@ source_set("c") {
"ppb_audio.h",
"ppb_audio_buffer.h",
"ppb_audio_config.h",
"ppb_audio_encoder.h",
"ppb_console.h",
"ppb_core.h",
"ppb_file_io.h",

@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
/* From pp_codecs.idl modified Fri Sep 18 10:42:55 2015. */
/* From pp_codecs.idl modified Fri Mar 29 17:59:41 2019. */
#ifndef PPAPI_C_PP_CODECS_H_
#define PPAPI_C_PP_CODECS_H_
@ -42,14 +42,6 @@ typedef enum {
PP_VIDEOPROFILE_MAX = PP_VIDEOPROFILE_VP9_ANY
} PP_VideoProfile;
/**
* Audio profiles.
*/
typedef enum {
PP_AUDIOPROFILE_OPUS = 0,
PP_AUDIOPROFILE_MAX = PP_AUDIOPROFILE_OPUS
} PP_AudioProfile;
/**
* Hardware acceleration options.
*/
@ -195,33 +187,6 @@ struct PP_VideoProfileDescription_0_1 {
PP_HardwareAcceleration acceleration;
};
/**
* Supported audio profile information. See the PPB_AudioEncoder function
* GetSupportedProfiles() for more details.
*/
struct PP_AudioProfileDescription {
/**
* The codec profile.
*/
PP_AudioProfile profile;
/**
* Maximum number of channels that can be encoded.
*/
uint32_t max_channels;
/**
* Sample size.
*/
uint32_t sample_size;
/**
* Sampling rate that can be encoded
*/
uint32_t sample_rate;
/**
* Whether the profile is hardware accelerated.
*/
PP_Bool hardware_accelerated;
};
/**
* Struct describing a bitstream buffer.
*/

@ -1,222 +0,0 @@
/* Copyright 2015 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* From ppb_audio_encoder.idl modified Mon Sep 7 10:17:53 2015. */
#ifndef PPAPI_C_PPB_AUDIO_ENCODER_H_
#define PPAPI_C_PPB_AUDIO_ENCODER_H_
#include "ppapi/c/pp_array_output.h"
#include "ppapi/c/pp_bool.h"
#include "ppapi/c/pp_codecs.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_macros.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/pp_stdint.h"
#include "ppapi/c/ppb_audio_buffer.h"
#define PPB_AUDIOENCODER_INTERFACE_0_1 "PPB_AudioEncoder;0.1" /* dev */
/**
* @file
* This file defines the <code>PPB_AudioEncoder</code> interface.
*/
/**
* @addtogroup Interfaces
* @{
*/
/**
* Audio encoder interface.
*
* Typical usage:
* - Call Create() to create a new audio encoder resource.
* - Call GetSupportedProfiles() to determine which codecs and profiles are
* available.
* - Call Initialize() to initialize the encoder for a supported profile.
* - Call GetBuffer() to get an empty buffer and fill it in, or get an audio
* buffer from another resource, e.g. <code>PPB_MediaStreamAudioTrack</code>.
* - Call Encode() to push the audio buffer to the encoder. If an external
* buffer is pushed, wait for completion to recycle the buffer.
* - Call GetBitstreamBuffer() continuously (waiting for each previous call to
* complete) to pull encoded buffers from the encoder.
* - Call RecycleBitstreamBuffer() after consuming the data in the bitstream
* buffer.
* - To destroy the encoder, the plugin should release all of its references to
* it. Any pending callbacks will abort before the encoder is destroyed.
*
* Available audio codecs vary by platform.
* All: opus.
*/
struct PPB_AudioEncoder_0_1 { /* dev */
/**
* Creates a new audio encoder resource.
*
* @param[in] instance A <code>PP_Instance</code> identifying the instance
* with the audio encoder.
*
* @return A <code>PP_Resource</code> corresponding to an audio encoder if
* successful or 0 otherwise.
*/
PP_Resource (*Create)(PP_Instance instance);
/**
* Determines if the given resource is an audio encoder.
*
* @param[in] resource A <code>PP_Resource</code> identifying a resource.
*
* @return <code>PP_TRUE</code> if the resource is a
* <code>PPB_AudioEncoder</code>, <code>PP_FALSE</code> if the resource is
* invalid or some other type.
*/
PP_Bool (*IsAudioEncoder)(PP_Resource resource);
/**
* Gets an array of supported audio encoder profiles.
* These can be used to choose a profile before calling Initialize().
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
* @param[in] output A <code>PP_ArrayOutput</code> to receive the supported
* <code>PP_AudioProfileDescription</code> structs.
* @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
* completion.
*
* @return If >= 0, the number of supported profiles returned, otherwise an
* error code from <code>pp_errors.h</code>.
*/
int32_t (*GetSupportedProfiles)(PP_Resource audio_encoder,
struct PP_ArrayOutput output,
struct PP_CompletionCallback callback);
/**
* Initializes an audio encoder resource. The plugin should call Initialize()
* successfully before calling any of the functions below.
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
* @param[in] channels The number of audio channels to encode.
* @param[in] input_sampling_rate The sampling rate of the input audio buffer.
* @param[in] input_sample_size The sample size of the input audio buffer.
* @param[in] output_profile A <code>PP_AudioProfile</code> specifying the
* codec profile of the encoded output stream.
* @param[in] initial_bitrate The initial bitrate for the encoder.
* @param[in] acceleration A <code>PP_HardwareAcceleration</code> specifying
* whether to use a hardware accelerated or a software implementation.
* @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
* completion.
*
* @return An int32_t containing an error code from <code>pp_errors.h</code>.
* Returns PP_ERROR_NOTSUPPORTED if audio encoding is not available, or the
* requested codec profile is not supported.
*/
int32_t (*Initialize)(PP_Resource audio_encoder,
uint32_t channels,
PP_AudioBuffer_SampleRate input_sample_rate,
PP_AudioBuffer_SampleSize input_sample_size,
PP_AudioProfile output_profile,
uint32_t initial_bitrate,
PP_HardwareAcceleration acceleration,
struct PP_CompletionCallback callback);
/**
* Gets the number of audio samples per channel that audio buffers must
* contain in order to be processed by the encoder. This will be the number of
* samples per channels contained in buffers returned by GetBuffer().
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
* @return An int32_t containing the number of samples required, or an error
* code from <code>pp_errors.h</code>.
* Returns PP_ERROR_FAILED if Initialize() has not successfully completed.
*/
int32_t (*GetNumberOfSamples)(PP_Resource audio_encoder);
/**
* Gets a blank audio buffer (with metadata given by the Initialize()
* call) which can be filled with audio data and passed to the encoder.
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
* @param[out] audio_buffer A blank <code>PPB_AudioBuffer</code> resource.
* @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
* completion.
*
* @return An int32_t containing an error code from <code>pp_errors.h</code>.
* Returns PP_ERROR_FAILED if Initialize() has not successfully completed.
*/
int32_t (*GetBuffer)(PP_Resource audio_encoder,
PP_Resource* audio_buffer,
struct PP_CompletionCallback callback);
/**
* Encodes an audio buffer.
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
* @param[in] audio_buffer The <code>PPB_AudioBuffer</code> to be encoded.
* @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
* completion. Plugins that pass <code>PPB_AudioBuffer</code> resources owned
* by other resources should wait for completion before reusing them.
*
* @return An int32_t containing an error code from <code>pp_errors.h</code>.
* Returns PP_ERROR_FAILED if Initialize() has not successfully completed.
*/
int32_t (*Encode)(PP_Resource audio_encoder,
PP_Resource audio_buffer,
struct PP_CompletionCallback callback);
/**
* Gets the next encoded bitstream buffer from the encoder.
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
* @param[out] bitstream_buffer A <code>PP_BitstreamBuffer</code> containing
* encoded audio data.
* @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
* completion. The plugin can call GetBitstreamBuffer from the callback in
* order to continuously "pull" bitstream buffers from the encoder.
*
* @return An int32_t containing an error code from <code>pp_errors.h</code>.
* Returns PP_ERROR_FAILED if Initialize() has not successfully completed.
* Returns PP_ERROR_INPROGRESS if a prior call to GetBitstreamBuffer() has
* not completed.
*/
int32_t (*GetBitstreamBuffer)(
PP_Resource audio_encoder,
struct PP_AudioBitstreamBuffer* bitstream_buffer,
struct PP_CompletionCallback callback);
/**
* Recycles a bitstream buffer back to the encoder.
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
* @param[in] bitstream_buffer A <code>PP_BitstreamBuffer</code> that is no
* longer needed by the plugin.
*/
void (*RecycleBitstreamBuffer)(
PP_Resource audio_encoder,
const struct PP_AudioBitstreamBuffer* bitstream_buffer);
/**
* Requests a change to the encoding bitrate. This is only a request,
* fulfilled on a best-effort basis.
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
* @param[in] bitrate The requested new bitrate, in bits per second.
*/
void (*RequestBitrateChange)(PP_Resource audio_encoder, uint32_t bitrate);
/**
* Closes the audio encoder, and cancels any pending encodes. Any pending
* callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> . It is
* not valid to call any encoder functions after a call to this method.
* <strong>Note:</strong> Destroying the audio encoder closes it implicitly,
* so you are not required to call Close().
*
* @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
* encoder.
*/
void (*Close)(PP_Resource audio_encoder);
};
/**
* @}
*/
#endif /* PPAPI_C_PPB_AUDIO_ENCODER_H_ */

@ -60,8 +60,6 @@ source_set("objects") {
"audio_buffer.h",
"audio_config.cc",
"audio_config.h",
"audio_encoder.cc",
"audio_encoder.h",
"completion_callback.h",
"core.cc",
"core.h",

@ -1,118 +0,0 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ppapi/cpp/audio_encoder.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/ppb_audio_encoder.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/instance_handle.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
namespace pp {
namespace {
template <>
const char* interface_name<PPB_AudioEncoder_0_1>() {
return PPB_AUDIOENCODER_INTERFACE_0_1;
}
} // namespace
AudioEncoder::AudioEncoder() {
}
AudioEncoder::AudioEncoder(const InstanceHandle& instance) {
if (has_interface<PPB_AudioEncoder_0_1>()) {
PassRefFromConstructor(
get_interface<PPB_AudioEncoder_0_1>()->Create(instance.pp_instance()));
}
}
AudioEncoder::AudioEncoder(const AudioEncoder& other) : Resource(other) {
}
int32_t AudioEncoder::GetSupportedProfiles(const CompletionCallbackWithOutput<
std::vector<PP_AudioProfileDescription> >& cc) {
if (has_interface<PPB_AudioEncoder_0_1>()) {
return get_interface<PPB_AudioEncoder_0_1>()->GetSupportedProfiles(
pp_resource(), cc.output(), cc.pp_completion_callback());
}
return cc.MayForce(PP_ERROR_NOINTERFACE);
}
int32_t AudioEncoder::Initialize(uint32_t channels,
PP_AudioBuffer_SampleRate input_sample_rate,
PP_AudioBuffer_SampleSize input_sample_size,
PP_AudioProfile output_profile,
uint32_t initial_bitrate,
PP_HardwareAcceleration acceleration,
const CompletionCallback& cc) {
if (has_interface<PPB_AudioEncoder_0_1>()) {
return get_interface<PPB_AudioEncoder_0_1>()->Initialize(
pp_resource(), channels, input_sample_rate, input_sample_size,
output_profile, initial_bitrate, acceleration,
cc.pp_completion_callback());
}
return cc.MayForce(PP_ERROR_NOINTERFACE);
}
int32_t AudioEncoder::GetNumberOfSamples() {
if (has_interface<PPB_AudioEncoder_0_1>()) {
return get_interface<PPB_AudioEncoder_0_1>()->GetNumberOfSamples(
pp_resource());
}
return PP_ERROR_NOINTERFACE;
}
int32_t AudioEncoder::GetBuffer(
const CompletionCallbackWithOutput<AudioBuffer>& cc) {
if (has_interface<PPB_AudioEncoder_0_1>()) {
return get_interface<PPB_AudioEncoder_0_1>()->GetBuffer(
pp_resource(), cc.output(), cc.pp_completion_callback());
}
return cc.MayForce(PP_ERROR_NOINTERFACE);
}
int32_t AudioEncoder::Encode(const AudioBuffer& audio_buffer,
const CompletionCallback& cc) {
if (has_interface<PPB_AudioEncoder_0_1>()) {
return get_interface<PPB_AudioEncoder_0_1>()->Encode(
pp_resource(), audio_buffer.pp_resource(), cc.pp_completion_callback());
}
return cc.MayForce(PP_ERROR_NOINTERFACE);
}
int32_t AudioEncoder::GetBitstreamBuffer(
const CompletionCallbackWithOutput<PP_AudioBitstreamBuffer>& cc) {
if (has_interface<PPB_AudioEncoder_0_1>()) {
return get_interface<PPB_AudioEncoder_0_1>()->GetBitstreamBuffer(
pp_resource(), cc.output(), cc.pp_completion_callback());
}
return cc.MayForce(PP_ERROR_NOINTERFACE);
}
void AudioEncoder::RecycleBitstreamBuffer(
const PP_AudioBitstreamBuffer& bitstream_buffer) {
if (has_interface<PPB_AudioEncoder_0_1>()) {
get_interface<PPB_AudioEncoder_0_1>()->RecycleBitstreamBuffer(
pp_resource(), &bitstream_buffer);
}
}
void AudioEncoder::RequestBitrateChange(uint32_t bitrate) {
if (has_interface<PPB_AudioEncoder_0_1>()) {
get_interface<PPB_AudioEncoder_0_1>()->RequestBitrateChange(pp_resource(),
bitrate);
}
}
void AudioEncoder::Close() {
if (has_interface<PPB_AudioEncoder_0_1>())
get_interface<PPB_AudioEncoder_0_1>()->Close(pp_resource());
}
} // namespace pp

@ -1,164 +0,0 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PPAPI_CPP_AUDIO_ENCODER_H_
#define PPAPI_CPP_AUDIO_ENCODER_H_
#include <stdint.h>
#include "ppapi/c/pp_codecs.h"
#include "ppapi/c/ppb_audio_buffer.h"
#include "ppapi/cpp/audio_buffer.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/resource.h"
/// @file
/// This file defines the API to create and use a AudioEncoder resource.
namespace pp {
class InstanceHandle;
/// Audio encoder interface.
///
/// Typical usage:
/// - Call Create() to create a new audio encoder resource.
/// - Call GetSupportedFormats() to determine which codecs and profiles are
/// available.
/// - Call Initialize() to initialize the encoder for a supported profile.
/// - Call GetBuffer() to get a blank frame and fill it in, or get an audio
/// frame from another resource, e.g. <code>PPB_MediaStreamAudioTrack</code>.
/// - Call Encode() to push the audio buffer to the encoder. If an external
/// buffer is pushed, wait for completion to recycle the frame.
/// - Call GetBitstreamBuffer() continuously (waiting for each previous call to
/// complete) to pull encoded buffers from the encoder.
/// - Call RecycleBitstreamBuffer() after consuming the data in the bitstream
/// buffer.
/// - To destroy the encoder, the plugin should release all of its references to
/// it. Any pending callbacks will abort before the encoder is destroyed.
///
/// Available audio codecs vary by platform.
/// All: opus.
class AudioEncoder : public Resource {
public:
/// Default constructor for creating an is_null() <code>AudioEncoder</code>
/// object.
AudioEncoder();
/// A constructor used to create a <code>AudioEncoder</code> and associate it
/// with the provided <code>Instance</code>.
/// @param[in] instance The instance with which this resource will be
/// associated.
explicit AudioEncoder(const InstanceHandle& instance);
/// The copy constructor for <code>AudioEncoder</code>.
/// @param[in] other A reference to a <code>AudioEncoder</code>.
AudioEncoder(const AudioEncoder& other);
/// Gets an array of supported audio encoder profiles.
/// These can be used to choose a profile before calling Initialize().
///
/// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
/// called upon completion with the PP_AudioProfileDescription structs.
///
/// @return If >= 0, the number of supported profiles returned, otherwise an
/// error code from <code>pp_errors.h</code>.
int32_t GetSupportedProfiles(const CompletionCallbackWithOutput<
std::vector<PP_AudioProfileDescription> >& cc);
/// Initializes a audio encoder resource. This should be called after
/// GetSupportedProfiles() and before any functions below.
///
/// @param[in] channels The number of audio channels to encode.
/// @param[in] input_sampling_rate The sampling rate of the input audio
/// buffer.
/// @param[in] input_sample_size The sample size of the input audio buffer.
/// @param[in] output_profile A <code>PP_AudioProfile</code> specifying the
/// codec profile of the encoded output stream.
/// @param[in] initial_bitrate The initial bitrate for the encoder.
/// @param[in] acceleration A <code>PP_HardwareAcceleration</code> specifying
/// whether to use a hardware accelerated or a software implementation.
/// @param[in] callback A <code>CompletionCallback</code> to be called upon
/// completion.
///
/// @return An int32_t containing an error code from <code>pp_errors.h</code>.
/// Returns PP_ERROR_NOTSUPPORTED if audio encoding is not available, or the
/// requested codec profile is not supported.
/// Returns PP_ERROR_NOMEMORY if bitstream buffers can't be created.
int32_t Initialize(uint32_t channels,
PP_AudioBuffer_SampleRate input_sample_rate,
PP_AudioBuffer_SampleSize input_sample_size,
PP_AudioProfile output_profile,
uint32_t initial_bitrate,
PP_HardwareAcceleration acceleration,
const CompletionCallback& cc);
/// Gets the number of audio samples per channel that audio buffers
/// must contain in order to be processed by the encoder. This will
/// be the number of samples per channels contained in buffers
/// returned by GetBuffer().
///
/// @return An int32_t containing the number of samples required, or an error
/// code from <code>pp_errors.h</code>.
/// Returns PP_ERROR_FAILED if Initialize() has not successfully completed.
int32_t GetNumberOfSamples();
/// Gets a blank audio frame which can be filled with audio data and passed
/// to the encoder.
///
/// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
/// called upon completion with the blank <code>AudioBuffer</code> resource.
///
/// @return An int32_t containing an error code from <code>pp_errors.h</code>.
int32_t GetBuffer(const CompletionCallbackWithOutput<AudioBuffer>& cc);
/// Encodes an audio buffer.
///
/// @param[in] audio_buffer The <code>AudioBuffer</code> to be encoded.
/// @param[in] callback A <code>CompletionCallback</code> to be called upon
/// completion. Plugins that pass <code>AudioBuffer</code> resources owned
/// by other resources should wait for completion before reusing them.
///
/// @return An int32_t containing an error code from <code>pp_errors.h</code>.
/// Returns PP_ERROR_FAILED if Initialize() has not successfully completed.
int32_t Encode(const AudioBuffer& buffer, const CompletionCallback& cc);
/// Gets the next encoded bitstream buffer from the encoder.
///
/// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
/// called upon completion with the next bitstream buffer. The plugin can call
/// GetBitstreamBuffer from the callback in order to continuously "pull"
/// bitstream buffers from the encoder.
///
/// @return An int32_t containing an error code from <code>pp_errors.h</code>.
/// Returns PP_ERROR_FAILED if Initialize() has not successfully completed.
/// Returns PP_ERROR_INPROGRESS if a prior call to GetBitstreamBuffer() has
/// not completed.
int32_t GetBitstreamBuffer(
const CompletionCallbackWithOutput<PP_AudioBitstreamBuffer>& cc);
/// Recycles a bitstream buffer back to the encoder.
///
/// @param[in] bitstream_buffer A<code>PP_AudioBitstreamBuffer</code> that
/// is no longer needed by the plugin.
void RecycleBitstreamBuffer(const PP_AudioBitstreamBuffer& bitstream_buffer);
/// Requests a change to the encoding bitrate. This is only a request,
/// fulfilled on a best-effort basis.
///
/// @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
/// encoder.
void RequestBitrateChange(uint32_t bitrate);
/// Closes the audio encoder, and cancels any pending encodes. Any pending
/// callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> . It is
/// not valid to call any encoder functions after a call to this method.
/// <strong>Note:</strong> Destroying the audio encoder closes it implicitly,
/// so you are not required to call Close().
void Close();
};
} // namespace pp
#endif // PPAPI_CPP_AUDIO_ENCODER_H_

@ -1,384 +0,0 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <string>
#include <vector>
#include "ppapi/cpp/audio_buffer.h"
#include "ppapi/cpp/audio_encoder.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/logging.h"
#include "ppapi/cpp/media_stream_audio_track.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/var_array_buffer.h"
#include "ppapi/cpp/var_dictionary.h"
#include "ppapi/utility/completion_callback_factory.h"
// When compiling natively on Windows, PostMessage can be #define-d to
// something else.
#ifdef PostMessage
#undef PostMessage
#endif
// This example demonstrates receiving audio samples from an audio
// track and encoding them.
namespace {
class AudioEncoderInstance : public pp::Instance {
public:
explicit AudioEncoderInstance(PP_Instance instance);
virtual ~AudioEncoderInstance();
private:
// pp::Instance implementation.
virtual void HandleMessage(const pp::Var& var_message);
std::string ProfileToString(PP_AudioProfile profile);
void GetSupportedProfiles();
void OnGetSupportedProfiles(
int32_t result,
const std::vector<PP_AudioProfileDescription> profiles);
void StartAudioTrack(const pp::Resource& resource_track);
void StopAudioTrack();
void OnGetBuffer(int32_t result, pp::AudioBuffer buffer);
void InitializeEncoder();
void OnEncoderInitialized(int32_t result);
void OnAudioTrackConfigured(int32_t result);
void GetEncoderBuffer(const pp::AudioBuffer& track_buffer);
void OnGetEncoderBuffer(int32_t result,
pp::AudioBuffer buffer,
pp::AudioBuffer track_buffer);
void OnEncodeDone(int32_t result);
void OnGetBitstreamBuffer(int32_t result,
const PP_AudioBitstreamBuffer& buffer);
pp::VarDictionary NewCommand(const std::string& type);
void Log(const std::string& message);
void LogError(int32_t error, const std::string& message);
void PostAudioFormat();
void PostDataMessage(const void* data, uint32_t size);
pp::CompletionCallbackFactory<AudioEncoderInstance> callback_factory_;
// Set when the plugin is not performing any encoding and just passing the
// uncompressed data directly to web page.
bool no_encoding_;
uint32_t channels_;
uint32_t sample_rate_;
uint32_t sample_size_;
uint32_t samples_per_frame_;
pp::MediaStreamAudioTrack audio_track_;
pp::AudioEncoder audio_encoder_;
};
AudioEncoderInstance::AudioEncoderInstance(PP_Instance instance)
: pp::Instance(instance),
callback_factory_(this),
no_encoding_(true),
channels_(0),
sample_rate_(0),
sample_size_(0),
samples_per_frame_(0),
audio_encoder_(this) {
GetSupportedProfiles();
}
AudioEncoderInstance::~AudioEncoderInstance() {}
void AudioEncoderInstance::HandleMessage(const pp::Var& var_message) {
if (!var_message.is_dictionary()) {
LogError(PP_ERROR_FAILED,
"Cannot handle incoming message, not a dictionary");
return;
}
pp::VarDictionary dict_message(var_message);
std::string command = dict_message.Get("command").AsString();
if (command == "start") {
pp::Var var_track = dict_message.Get("track");
if (!var_track.is_resource()) {
LogError(PP_ERROR_FAILED, "Given track is not a resource");
return;
}
std::string profile = dict_message.Get("profile").AsString();
if (profile == "wav") {
no_encoding_ = true;
} else {
no_encoding_ = false;
}
StartAudioTrack(var_track.AsResource());
} else if (command == "stop") {
StopAudioTrack();
} else {
LogError(PP_ERROR_FAILED, "Invalid command");
}
}
std::string AudioEncoderInstance::ProfileToString(PP_AudioProfile profile) {
if (profile == PP_AUDIOPROFILE_OPUS)
return "opus";
return "unknown";
}
void AudioEncoderInstance::GetSupportedProfiles() {
audio_encoder_.GetSupportedProfiles(callback_factory_.NewCallbackWithOutput(
&AudioEncoderInstance::OnGetSupportedProfiles));
}
void AudioEncoderInstance::OnGetSupportedProfiles(
int32_t result,
const std::vector<PP_AudioProfileDescription> profiles) {
pp::VarDictionary dictionary = NewCommand("supportedProfiles");
pp::VarArray js_profiles;
dictionary.Set(pp::Var("profiles"), js_profiles);
if (result < 0) {
LogError(result, "Cannot get supported profiles");
PostMessage(dictionary);
}
int32_t idx = 0;
for (std::vector<PP_AudioProfileDescription>::const_iterator it =
profiles.begin();
it != profiles.end(); ++it) {
pp::VarDictionary js_profile;
js_profile.Set(pp::Var("name"), pp::Var(ProfileToString(it->profile)));
js_profile.Set(pp::Var("sample_size"),
pp::Var(static_cast<int32_t>(it->sample_size)));
js_profile.Set(pp::Var("sample_rate"),
pp::Var(static_cast<int32_t>(it->sample_rate)));
js_profiles.Set(idx++, js_profile);
}
PostMessage(dictionary);
}
void AudioEncoderInstance::StartAudioTrack(const pp::Resource& resource_track) {
audio_track_ = pp::MediaStreamAudioTrack(resource_track);
audio_track_.GetBuffer(callback_factory_.NewCallbackWithOutput(
&AudioEncoderInstance::OnGetBuffer));
}
void AudioEncoderInstance::StopAudioTrack() {
channels_ = 0;
audio_track_.Close();
audio_track_ = pp::MediaStreamAudioTrack();
audio_encoder_.Close();
audio_encoder_ = pp::AudioEncoder();
}
void AudioEncoderInstance::OnGetBuffer(int32_t result, pp::AudioBuffer buffer) {
if (result == PP_ERROR_ABORTED)
return;
if (result != PP_OK) {
LogError(result, "Cannot get audio track buffer");
return;
}
// If this is the first buffer, then we need to initialize the encoder.
if (channels_ == 0) {
channels_ = buffer.GetNumberOfChannels();
sample_rate_ = buffer.GetSampleRate();
sample_size_ = buffer.GetSampleSize();
samples_per_frame_ = buffer.GetNumberOfSamples();
if (no_encoding_) {
PostAudioFormat();
PostDataMessage(buffer.GetDataBuffer(), buffer.GetDataBufferSize());
audio_track_.GetBuffer(callback_factory_.NewCallbackWithOutput(
&AudioEncoderInstance::OnGetBuffer));
} else {
InitializeEncoder();
}
// Given that once the encoder is initialized we might reconfigure the
// media track, we discard the first buffer to keep this example a bit
// simpler.
audio_track_.RecycleBuffer(buffer);
} else {
if (no_encoding_) {
PostDataMessage(buffer.GetDataBuffer(), buffer.GetDataBufferSize());
audio_track_.RecycleBuffer(buffer);
} else {
GetEncoderBuffer(buffer);
}
audio_track_.GetBuffer(callback_factory_.NewCallbackWithOutput(
&AudioEncoderInstance::OnGetBuffer));
}
}
void AudioEncoderInstance::InitializeEncoder() {
if (audio_encoder_.is_null())
audio_encoder_ = pp::AudioEncoder(this);
audio_encoder_.Initialize(
channels_, static_cast<PP_AudioBuffer_SampleRate>(sample_rate_),
static_cast<PP_AudioBuffer_SampleSize>(sample_size_),
PP_AUDIOPROFILE_OPUS, 100000, PP_HARDWAREACCELERATION_WITHFALLBACK,
callback_factory_.NewCallback(
&AudioEncoderInstance::OnEncoderInitialized));
}
void AudioEncoderInstance::OnEncoderInitialized(int32_t result) {
if (result == PP_ERROR_ABORTED)
return;
if (result != PP_OK) {
LogError(result, "Cannot initialize encoder");
return;
}
int32_t attribs[] = {
// Duration in milliseconds.
PP_MEDIASTREAMAUDIOTRACK_ATTRIB_DURATION,
1000 / (sample_rate_ / audio_encoder_.GetNumberOfSamples()),
PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE};
audio_track_.Configure(attribs,
callback_factory_.NewCallback(
&AudioEncoderInstance::OnAudioTrackConfigured));
samples_per_frame_ = audio_encoder_.GetNumberOfSamples();
PostAudioFormat();
}
void AudioEncoderInstance::OnAudioTrackConfigured(int32_t result) {
if (result == PP_ERROR_ABORTED)
return;
if (result != PP_OK) {
LogError(result, "Cannot configure audio track buffer duration");
return;
}
audio_track_.GetBuffer(callback_factory_.NewCallbackWithOutput(
&AudioEncoderInstance::OnGetBuffer));
audio_encoder_.GetBitstreamBuffer(callback_factory_.NewCallbackWithOutput(
&AudioEncoderInstance::OnGetBitstreamBuffer));
}
void AudioEncoderInstance::GetEncoderBuffer(
const pp::AudioBuffer& track_buffer) {
audio_encoder_.GetBuffer(callback_factory_.NewCallbackWithOutput(
&AudioEncoderInstance::OnGetEncoderBuffer, track_buffer));
}
void AudioEncoderInstance::OnGetEncoderBuffer(int32_t result,
pp::AudioBuffer buffer,
pp::AudioBuffer track_buffer) {
const char* error(nullptr);
if (result != PP_OK)
error = "Cannot get encoder buffer";
if (buffer.GetDataBufferSize() != track_buffer.GetDataBufferSize()) {
result = PP_ERROR_FAILED;
error = "Invalid buffer size";
}
if (result == PP_OK) {
memcpy(buffer.GetDataBuffer(), track_buffer.GetDataBuffer(),
buffer.GetDataBufferSize());
audio_encoder_.Encode(buffer, callback_factory_.NewCallback(
&AudioEncoderInstance::OnEncodeDone));
} else {
LogError(result, error);
StopAudioTrack();
}
audio_track_.RecycleBuffer(track_buffer);
}
void AudioEncoderInstance::OnEncodeDone(int32_t result) {}
void AudioEncoderInstance::OnGetBitstreamBuffer(
int32_t result,
const PP_AudioBitstreamBuffer& buffer) {
if (result == PP_ERROR_ABORTED)
return;
if (result != PP_OK) {
LogError(result, "Cannot get bitstream buffer");
return;
}
audio_encoder_.GetBitstreamBuffer(callback_factory_.NewCallbackWithOutput(
&AudioEncoderInstance::OnGetBitstreamBuffer));
PostDataMessage(buffer.buffer, buffer.size);
audio_encoder_.RecycleBitstreamBuffer(buffer);
}
pp::VarDictionary AudioEncoderInstance::NewCommand(const std::string& type) {
pp::VarDictionary dictionary;
dictionary.Set(pp::Var("command"), pp::Var(type));
return dictionary;
}
void AudioEncoderInstance::Log(const std::string& message) {
pp::VarDictionary dictionary = NewCommand("log");
dictionary.Set(pp::Var("message"), pp::Var(message));
PostMessage(dictionary);
}
void AudioEncoderInstance::LogError(int32_t error, const std::string& message) {
pp::VarDictionary dictionary = NewCommand("error");
std::string msg("Error: ");
msg.append(message);
msg.append(" : ");
msg.append(pp::Var(error).DebugString());
dictionary.Set(pp::Var("message"), pp::Var(msg));
PostMessage(dictionary);
}
void AudioEncoderInstance::PostAudioFormat() {
pp::VarDictionary dictionary = NewCommand("format");
dictionary.Set(pp::Var("channels"), pp::Var(static_cast<int32_t>(channels_)));
dictionary.Set(pp::Var("sample_rate"),
pp::Var(static_cast<int32_t>(sample_rate_)));
dictionary.Set(pp::Var("sample_size"),
pp::Var(static_cast<int32_t>(sample_size_)));
dictionary.Set(pp::Var("sample_per_frame"),
pp::Var(static_cast<int32_t>(samples_per_frame_)));
PostMessage(dictionary);
}
void AudioEncoderInstance::PostDataMessage(const void* data, uint32_t size) {
pp::VarDictionary dictionary = NewCommand("data");
uint8_t* buffer;
pp::VarArrayBuffer array_buffer = pp::VarArrayBuffer(size);
buffer = static_cast<uint8_t*>(array_buffer.Map());
memcpy(buffer, data, size);
array_buffer.Unmap();
dictionary.Set(pp::Var("buffer"), array_buffer);
PostMessage(dictionary);
}
class AudioEncoderModule : public pp::Module {
public:
virtual pp::Instance* CreateInstance(PP_Instance instance) {
return new AudioEncoderInstance(instance);
}
};
} // namespace
namespace pp {
// Factory function for your specialization of the Module object.
Module* CreateModule() {
return new AudioEncoderModule();
}
} // namespace pp

@ -1,418 +0,0 @@
<!DOCTYPE html>
<html>
<!--
Copyright 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
<title>Audio Encoder Example</title>
<script type="text/javascript">
var plugin;
var track;
var writer;
var profiles;
function writeString(array, offset, string) {
for (var i = 0; i < string.length; i++)
array.set([string.charCodeAt(i)], i + offset);
return string.length;
}
function writeValue(array, bytes, offset, value) {
for (var i = 0; i < bytes; i++)
array.set([((value >>> (i * 8)) & 0xff)], offset + i);
return bytes;
}
var BufferArray = function() {
this._arrays = [ this._createBuffer() ];
};
BufferArray.prototype = {
_createBuffer: function() {
var buffer = new Uint8Array(100 * 1024);
buffer.dataLength = 0;
return buffer;
},
appendData: function(data) {
var currentBuffer = this._arrays[this._arrays.length - 1];
if (currentBuffer.byteLength < (currentBuffer.dataLength + data.byteLength)) {
this._arrays.push(this._createBuffer());
currentBuffer = this._arrays[this._arrays.length - 1];
}
currentBuffer.set(new Uint8Array(data), currentBuffer.dataLength);
currentBuffer.dataLength += data.byteLength;
},
getByte: function(offset) {
var bufferOffset = 0;
for (var i = 0; i < this._arrays.length; i++) {
var buffer = this._arrays[i];
if (offset < (bufferOffset + buffer.dataLength)) {
return buffer[offset - bufferOffset];
}
bufferOffset += buffer.dataLength;
}
throw new Error('Out of range access');
},
getSize: function() {
var size = 0;
for (var i = 0; i < this._arrays.length; i++)
size += this._arrays[i].dataLength;
return size;
},
writeValue: function(bytes, offset, value) {
var bufferOffset = 0;
for (var i = 0; i < this._arrays.length; i++) {
var buffer = this._arrays[i];
if (offset < (bufferOffset + buffer.dataLength)) {
writeValue(buffer, bytes, offset - bufferOffset, value);
return;
}
bufferOffset += buffer.dataLength;
}
throw new Error('Out of range access');
},
toBlob: function() {
var result = new Uint8Array(this.getSize());
var offset = 0;
for (var i = 0; i < this._arrays.length; i++) {
var buffer = this._arrays[i];
result.set(buffer.subarray(0, buffer.dataLength), offset);
offset += buffer.dataLength;
}
return new Blob([result]);
},
};
// Writes wav data.
var WavWriter = function() {
this.chunkSizeOffset = 0;
this.buffer = new BufferArray();
};
WavWriter.prototype = {
writeHeader: function(format) {
var buffer =
new Uint8Array(4 + 4 + 4 + 4 + 4 + 2 + 2 + 4 + 4 + 2 + 2 + 4 + 4);
var i = 0;
// File header
i += writeString(buffer, i, 'RIFF');
i += 4; // Gap for final size.
i += writeString(buffer, i, 'WAVE');
// Chunk ID.
i += writeString(buffer, i, 'fmt ');
// Chunk length.
i += writeValue(buffer, 4, i, 16);
// Codec (uncompressed LPCM).
i += writeValue(buffer, 2, i, 1);
// Number of channels.
i += writeValue(buffer, 2, i, format.channels);
// Sample rate.
i += writeValue(buffer, 4, i, format.sample_rate);
// Average bytes per seconds (sample rate * bytes per sample)
i += writeValue(buffer, 4, i,
format.sample_rate * format.sample_size);
// Bytes per sample.
i += writeValue(buffer, 2, i,
format.sample_size * format.channels);
// Bits per sample.
i += writeValue(buffer, 2, i, format.sample_size * 8);
// Data chunk
i += writeString(buffer, i, 'data');
this.chunkSizeOffset = i; // Location of the chunk's size
this.buffer.appendData(buffer);
},
writeData: function(data) {
this.buffer.appendData(data);
},
end: function() {
this.buffer.writeValue(4, 4, this.buffer.getSize() - 8);
this.buffer.writeValue(4, this.chunkSizeOffset,
this.buffer.getSize() - this.chunkSizeOffset);
},
getSize: function() {
return this.buffer.getSize();
},
getData: function() {
return this.buffer;
},
getExtension: function() {
return 'wav';
},
};
// Writes ogg data.
var OggWriter = function(profile) {
this.writeHeader = this._writeOpusHeader;
this.buffer = new BufferArray();
this.pageSequence = 0;
this.bitstreamNumber = 0;
this.position = 0;
this.dataWritten = false;
};
OggWriter.prototype = {
_Start: 0x2,
_Continue: 0x1,
_Stop: 0x4,
_makeCRCTable: function() {
var crcTable = [];
for (var n = 0; n < 256; n++) {
var r = n << 24;
for (var i = 0; i < 8; i++) {
if (r & 0x80000000)
r = (r << 1) ^ 0x04c11db7;
else
r <<= 1;
}
crcTable[n] = r & 0xffffffff;
}
return crcTable;
},
_crc32: function(data, start, end) {
var crc = 0;
var crcTable = this._crcTable || (this._crcTable = this._makeCRCTable());
for (var i = start; i < end; i++)
crc = (crc << 8) ^ crcTable[((crc >> 24) & 0xff) ^ data.getByte(i)];
return crc;
},
_writePage: function(flag, size, position) {
var pages = 1 + Math.floor(size / 255);
var buffer = new Uint8Array(27 + pages), i = 0;
// capture_pattern.
i += writeString(buffer, i, 'OggS');
// stream_structure_version.
i += writeValue(buffer, 1, i, 0);
// header_type_flag.
i += writeValue(buffer, 1, i, flag);
// granule_position.
// TODO(llandwerlin): Not writing more than 32bits for now,
// because Javascript doesn't have 64bits integers, this limits
// the duration to ~24 hours at 48kHz sampling rate.
i += writeValue(buffer, 4, i, position != undefined ? position : 0);
i += writeValue(buffer, 4, i, 0);
// bitstream_serial_number.
i += writeValue(buffer, 4, i, this.bitstreamNumber);
// page_sequence_number.
i += writeValue(buffer, 4, i, this.pageSequence++);
// CRC_checksum.
i += writeValue(buffer, 4, i, 0);
// number_page_segments.
i += writeValue(buffer, 1, i, pages);
// segment sizes.
for (var j = 0; j < (pages - 1); j++)
i += writeValue(buffer, 1, i, 255);
i += writeValue(buffer, 1, i, size % 255);
this.buffer.appendData(buffer);
},
_writePageChecksum: function(pageOffset) {
var crc = this._crc32(this.buffer, pageOffset,
this.buffer.getSize());
this.buffer.writeValue(4, pageOffset + 22, crc);
},
_writeOpusHeader: function(format) {
this.format = format;
var start = this.buffer.getSize();
var buffer = new Uint8Array(8 + 1 + 1 + 2 + 4 + 2 + 1), i = 0;
// Opus header.
i += writeString(buffer, i, 'OpusHead');
// version.
i += writeValue(buffer, 1, i, 1);
// channel count.
i += writeValue(buffer, 1, i, format.channels);
// pre-skip.
i += writeValue(buffer, 2, i, 0);
// input sample rate.
i += writeValue(buffer, 4, i, format.sample_rate);
// output gain.
i += writeValue(buffer, 2, i, 0);
// channel mapping family.
i += writeValue(buffer, 1, i, 0);
this._writePage(this._Start, buffer.byteLength);
this.buffer.appendData(buffer);
this._writePageChecksum(start);
this._writeCommentHeader();
},
_writeCommentHeader: function(name) {
var start = this.buffer.getSize();
var buffer = new Uint8Array(8 + 4 + 8 + 4 + 4 + 13), i = 0;
// Opus comment header.
i += writeString(buffer, i, 'OpusTags');
// Vendor string.
i += this._writeLengthString(buffer, i, 'Chromium');
// User comment list length
i += writeValue(buffer, 4, i, 1);
// User comment 0 length.
i += this._writeLengthString(buffer, i, 'TITLE=example');
this._writePage(0, buffer.byteLength);
this.buffer.appendData(buffer);
this._writePageChecksum(start);
},
_writeLengthString: function(buffer, offset, str) {
return (writeValue(buffer, 4, offset, str.length) +
writeString(buffer, offset + 4, str));
},
writeData: function(data) {
this.position += this.format.sample_per_frame / this.format.channels;
var start = this.buffer.getSize();
this._writePage(0, data.byteLength, this.position);
this.buffer.appendData(data);
this._writePageChecksum(start);
this.dataWritten = true;
},
end: function() {
this._writePage(this._Stop, 0);
},
getData: function() {
return this.buffer;
},
getExtension: function() {
return 'ogg';
},
};
function $(id) {
return document.getElementById(id);
}
function success(stream) {
track = stream.getAudioTracks()[0];
var list = $('profileList');
var profile = profiles[list.selectedIndex];
plugin.postMessage({
command: 'start',
profile: profile.name,
sample_size: profile.sample_size,
sample_rate: profile.sample_rate,
track: track,
});
}
function failure(e) {
console.log("Error: ", e);
}
function cleanupDownload() {
var download = $('download');
if (!download)
return;
download.parentNode.removeChild(download);
}
function setDownload(blob, filename) {
var mimeType = 'application/octet-stream';
var a = document.createElement('a');
a.id = "download";
a.download = filename;
a.href = window.URL.createObjectURL(blob);
a.textContent = 'Download';
a.dataset.downloadurl = [mimeType, a.download, a.href].join(':');
$('download-box').appendChild(a);
}
function startRecord() {
var list = $('profileList');
var profile = profiles[list.selectedIndex];
if (profile.name == 'wav')
writer = new WavWriter();
else
writer = new OggWriter(profile);
cleanupDownload();
var constraints = [];
if (profile.name == 'opus') {
// Chromium outputs 32kHz sampling rate by default. This isn't a
// supported sampling rate for the Opus codec. So we force the
// output to 48kHz. If Chromium implements the GetUserMedia
// audio constraints at some point, we could potentially get rid
// of this.
constraints.push({ googAudioProcessing48kHzSupport: true });
}
navigator.webkitGetUserMedia({ audio: { optional: constraints },
video: false},
success, failure);
}
function stopRecord() {
plugin.postMessage({
command: "stop"
});
track.stop();
writer.end();
setDownload(writer.getData().toBlob(),
'Capture.' + writer.getExtension());
}
function handleMessage(msg) {
if (msg.data.command == 'log') {
console.log(msg.data.message);
} else if (msg.data.command == 'error') {
console.error(msg.data.message);
} else if (msg.data.command == 'data') {
writer.writeData(msg.data.buffer);
$('length').textContent = ' Size: ' + writer.getData().getSize() + ' bytes';
} else if (msg.data.command == 'format') {
writer.writeHeader(msg.data);
$('length').textContent = ' Size: ' + writer.getData().getSize() + ' bytes';
} else if (msg.data.command == 'supportedProfiles') {
profiles = [];
var profileList = $('profileList');
while (profileList.lastChild)
profileList.remove(profileList.lastChild);
var item = document.createElement('option');
item.label = 'wav';
profiles.push({ name: 'wav',
sample_rate: 0,
sample_size: 0,
sample_per_frame:
msg.data.profiles[0].sample_per_frame });
profileList.appendChild(item);
for (var i = 0; i < msg.data.profiles.length; i++) {
var item = document.createElement('option');
item.label = msg.data.profiles[i].name + ' - ' +
msg.data.profiles[i].sample_rate + 'Hz';
profiles.push(msg.data.profiles[i]);
profileList.appendChild(item);
}
}
}
function resetData() {
writer = new WavWriter();
$('length').textContent = ' Size: ' + writer.getData().getSize() + ' bytes';
}
function initialize() {
plugin = $('plugin');
plugin.addEventListener('message', handleMessage, false);
$('start').addEventListener('click', function (e) {
resetData();
startRecord();
});
$('stop').addEventListener('click', function (e) {
stopRecord();
});
}
document.addEventListener('DOMContentLoaded', initialize, false);
</script>
</head>
<body>
<h1>Pepper Audio Encoder API Example</h1><br>
This example demonstrates receiving frames from an audio MediaStreamTrack and
encoding them using AudioEncode.<br>
<select id="profileList"></select>
<input type="button" id="start" value="Start Recording"/>
<input type="button" id="stop" value="Stop Recording"/>
<div id="download-box"></div>
<div id="length"></div>
<br>
<embed id="plugin" type="application/x-ppapi-example-audio-encode"/>
</body>
</html>

@ -16,7 +16,6 @@
#include "ppapi/c/dev/ppb_url_util_dev.h"
#include "ppapi/c/dev/ppb_video_capture_dev.h"
#include "ppapi/c/dev/ppb_video_decoder_dev.h"
#include "ppapi/c/ppb_audio_encoder.h"
#include "ppapi/c/ppb_console.h"
#include "ppapi/c/ppb_core.h"
#include "ppapi/c/ppb_file_io.h"
@ -81,7 +80,6 @@ static int mystrcmp(const char* s1, const char *s2) {
/* BEGIN Declarations for all Wrapper Infos */
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_AudioEncoder_0_1;
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Console_1_0;
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Core_1_0;
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_FileIO_1_0;
@ -187,65 +185,6 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPP_Instance_Private_0_1;
/* Not generating wrapper methods for PPB_AudioConfig_1_1 */
/* Begin wrapper methods for PPB_AudioEncoder_0_1 */
static PP_Resource Pnacl_M47_PPB_AudioEncoder_Create(PP_Instance instance) {
const struct PPB_AudioEncoder_0_1 *iface = Pnacl_WrapperInfo_PPB_AudioEncoder_0_1.real_iface;
return iface->Create(instance);
}
static PP_Bool Pnacl_M47_PPB_AudioEncoder_IsAudioEncoder(PP_Resource resource) {
const struct PPB_AudioEncoder_0_1 *iface = Pnacl_WrapperInfo_PPB_AudioEncoder_0_1.real_iface;
return iface->IsAudioEncoder(resource);
}
static int32_t Pnacl_M47_PPB_AudioEncoder_GetSupportedProfiles(PP_Resource audio_encoder, struct PP_ArrayOutput* output, struct PP_CompletionCallback* callback) {
const struct PPB_AudioEncoder_0_1 *iface = Pnacl_WrapperInfo_PPB_AudioEncoder_0_1.real_iface;
return iface->GetSupportedProfiles(audio_encoder, *output, *callback);
}
static int32_t Pnacl_M47_PPB_AudioEncoder_Initialize(PP_Resource audio_encoder, uint32_t channels, PP_AudioBuffer_SampleRate input_sample_rate, PP_AudioBuffer_SampleSize input_sample_size, PP_AudioProfile output_profile, uint32_t initial_bitrate, PP_HardwareAcceleration acceleration, struct PP_CompletionCallback* callback) {
const struct PPB_AudioEncoder_0_1 *iface = Pnacl_WrapperInfo_PPB_AudioEncoder_0_1.real_iface;
return iface->Initialize(audio_encoder, channels, input_sample_rate, input_sample_size, output_profile, initial_bitrate, acceleration, *callback);
}
static int32_t Pnacl_M47_PPB_AudioEncoder_GetNumberOfSamples(PP_Resource audio_encoder) {
const struct PPB_AudioEncoder_0_1 *iface = Pnacl_WrapperInfo_PPB_AudioEncoder_0_1.real_iface;
return iface->GetNumberOfSamples(audio_encoder);
}
static int32_t Pnacl_M47_PPB_AudioEncoder_GetBuffer(PP_Resource audio_encoder, PP_Resource* audio_buffer, struct PP_CompletionCallback* callback) {
const struct PPB_AudioEncoder_0_1 *iface = Pnacl_WrapperInfo_PPB_AudioEncoder_0_1.real_iface;
return iface->GetBuffer(audio_encoder, audio_buffer, *callback);
}
static int32_t Pnacl_M47_PPB_AudioEncoder_Encode(PP_Resource audio_encoder, PP_Resource audio_buffer, struct PP_CompletionCallback* callback) {
const struct PPB_AudioEncoder_0_1 *iface = Pnacl_WrapperInfo_PPB_AudioEncoder_0_1.real_iface;
return iface->Encode(audio_encoder, audio_buffer, *callback);
}
static int32_t Pnacl_M47_PPB_AudioEncoder_GetBitstreamBuffer(PP_Resource audio_encoder, struct PP_AudioBitstreamBuffer* bitstream_buffer, struct PP_CompletionCallback* callback) {
const struct PPB_AudioEncoder_0_1 *iface = Pnacl_WrapperInfo_PPB_AudioEncoder_0_1.real_iface;
return iface->GetBitstreamBuffer(audio_encoder, bitstream_buffer, *callback);
}
static void Pnacl_M47_PPB_AudioEncoder_RecycleBitstreamBuffer(PP_Resource audio_encoder, const struct PP_AudioBitstreamBuffer* bitstream_buffer) {
const struct PPB_AudioEncoder_0_1 *iface = Pnacl_WrapperInfo_PPB_AudioEncoder_0_1.real_iface;
iface->RecycleBitstreamBuffer(audio_encoder, bitstream_buffer);
}
static void Pnacl_M47_PPB_AudioEncoder_RequestBitrateChange(PP_Resource audio_encoder, uint32_t bitrate) {
const struct PPB_AudioEncoder_0_1 *iface = Pnacl_WrapperInfo_PPB_AudioEncoder_0_1.real_iface;
iface->RequestBitrateChange(audio_encoder, bitrate);
}
static void Pnacl_M47_PPB_AudioEncoder_Close(PP_Resource audio_encoder) {
const struct PPB_AudioEncoder_0_1 *iface = Pnacl_WrapperInfo_PPB_AudioEncoder_0_1.real_iface;
iface->Close(audio_encoder);
}
/* End wrapper methods for PPB_AudioEncoder_0_1 */
/* Begin wrapper methods for PPB_Console_1_0 */
static void Pnacl_M25_PPB_Console_Log(PP_Instance instance, PP_LogLevel level, struct PP_Var* value) {
@ -3851,20 +3790,6 @@ static struct PP_Var Pnacl_M18_PPP_Instance_Private_GetInstanceObject(PP_Instanc
/* Not generating wrapper interface for PPB_AudioConfig_1_1 */
static const struct PPB_AudioEncoder_0_1 Pnacl_Wrappers_PPB_AudioEncoder_0_1 = {
.Create = (PP_Resource (*)(PP_Instance instance))&Pnacl_M47_PPB_AudioEncoder_Create,
.IsAudioEncoder = (PP_Bool (*)(PP_Resource resource))&Pnacl_M47_PPB_AudioEncoder_IsAudioEncoder,
.GetSupportedProfiles = (int32_t (*)(PP_Resource audio_encoder, struct PP_ArrayOutput output, struct PP_CompletionCallback callback))&Pnacl_M47_PPB_AudioEncoder_GetSupportedProfiles,
.Initialize = (int32_t (*)(PP_Resource audio_encoder, uint32_t channels, PP_AudioBuffer_SampleRate input_sample_rate, PP_AudioBuffer_SampleSize input_sample_size, PP_AudioProfile output_profile, uint32_t initial_bitrate, PP_HardwareAcceleration acceleration, struct PP_CompletionCallback callback))&Pnacl_M47_PPB_AudioEncoder_Initialize,
.GetNumberOfSamples = (int32_t (*)(PP_Resource audio_encoder))&Pnacl_M47_PPB_AudioEncoder_GetNumberOfSamples,
.GetBuffer = (int32_t (*)(PP_Resource audio_encoder, PP_Resource* audio_buffer, struct PP_CompletionCallback callback))&Pnacl_M47_PPB_AudioEncoder_GetBuffer,
.Encode = (int32_t (*)(PP_Resource audio_encoder, PP_Resource audio_buffer, struct PP_CompletionCallback callback))&Pnacl_M47_PPB_AudioEncoder_Encode,
.GetBitstreamBuffer = (int32_t (*)(PP_Resource audio_encoder, struct PP_AudioBitstreamBuffer* bitstream_buffer, struct PP_CompletionCallback callback))&Pnacl_M47_PPB_AudioEncoder_GetBitstreamBuffer,
.RecycleBitstreamBuffer = (void (*)(PP_Resource audio_encoder, const struct PP_AudioBitstreamBuffer* bitstream_buffer))&Pnacl_M47_PPB_AudioEncoder_RecycleBitstreamBuffer,
.RequestBitrateChange = (void (*)(PP_Resource audio_encoder, uint32_t bitrate))&Pnacl_M47_PPB_AudioEncoder_RequestBitrateChange,
.Close = (void (*)(PP_Resource audio_encoder))&Pnacl_M47_PPB_AudioEncoder_Close
};
static const struct PPB_Console_1_0 Pnacl_Wrappers_PPB_Console_1_0 = {
.Log = (void (*)(PP_Instance instance, PP_LogLevel level, struct PP_Var value))&Pnacl_M25_PPB_Console_Log,
.LogWithSource = (void (*)(PP_Instance instance, PP_LogLevel level, struct PP_Var source, struct PP_Var value))&Pnacl_M25_PPB_Console_LogWithSource
@ -4877,12 +4802,6 @@ static const struct PPP_Instance_Private_0_1 Pnacl_Wrappers_PPP_Instance_Private
/* Not generating wrapper interface for PPP_PexeStreamHandler_1_0 */
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_AudioEncoder_0_1 = {
.iface_macro = PPB_AUDIOENCODER_INTERFACE_0_1,
.wrapped_iface = (const void *) &Pnacl_Wrappers_PPB_AudioEncoder_0_1,
.real_iface = NULL
};
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Console_1_0 = {
.iface_macro = PPB_CONSOLE_INTERFACE_1_0,
.wrapped_iface = (const void *) &Pnacl_Wrappers_PPB_Console_1_0,
@ -5442,7 +5361,6 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPP_Instance_Private_0_1 = {
};
static struct __PnaclWrapperInfo *s_ppb_wrappers[] = {
&Pnacl_WrapperInfo_PPB_AudioEncoder_0_1,
&Pnacl_WrapperInfo_PPB_Console_1_0,
&Pnacl_WrapperInfo_PPB_Core_1_0,
&Pnacl_WrapperInfo_PPB_FileIO_1_0,

@ -21,8 +21,6 @@ component("proxy") {
"../utility/completion_callback_factory.h",
"audio_buffer_resource.cc",
"audio_buffer_resource.h",
"audio_encoder_resource.cc",
"audio_encoder_resource.h",
"broker_resource.cc",
"broker_resource.h",
"camera_capabilities_resource.cc",

@ -1,126 +0,0 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PPAPI_PROXY_AUDIO_ENCODER_RESOURCE_H_
#define PPAPI_PROXY_AUDIO_ENCODER_RESOURCE_H_
#include <stdint.h>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "ppapi/proxy/connection.h"
#include "ppapi/proxy/plugin_resource.h"
#include "ppapi/shared_impl/media_stream_buffer_manager.h"
#include "ppapi/shared_impl/resource.h"
#include "ppapi/thunk/ppb_audio_encoder_api.h"
namespace ppapi {
class TrackedCallback;
namespace proxy {
class AudioBufferResource;
class PPAPI_PROXY_EXPORT AudioEncoderResource
: public PluginResource,
public thunk::PPB_AudioEncoder_API,
public ppapi::MediaStreamBufferManager::Delegate {
public:
AudioEncoderResource(Connection connection, PP_Instance instance);
~AudioEncoderResource() override;
thunk::PPB_AudioEncoder_API* AsPPB_AudioEncoder_API() override;
private:
// MediaStreamBufferManager::Delegate implementation.
void OnNewBufferEnqueued() override {}
// PPB_AudioEncoder_API implementation.
int32_t GetSupportedProfiles(
const PP_ArrayOutput& output,
const scoped_refptr<TrackedCallback>& callback) override;
int32_t Initialize(uint32_t channels,
PP_AudioBuffer_SampleRate input_sample_rate,
PP_AudioBuffer_SampleSize input_sample_size,
PP_AudioProfile output_profile,
uint32_t initial_bitrate,
PP_HardwareAcceleration acceleration,
const scoped_refptr<TrackedCallback>& callback) override;
int32_t GetNumberOfSamples() override;
int32_t GetBuffer(PP_Resource* audio_buffer,
const scoped_refptr<TrackedCallback>& callback) override;
int32_t Encode(PP_Resource audio_buffer,
const scoped_refptr<TrackedCallback>& callback) override;
int32_t GetBitstreamBuffer(
PP_AudioBitstreamBuffer* bitstream_buffer,
const scoped_refptr<TrackedCallback>& callback) override;
void RecycleBitstreamBuffer(
const PP_AudioBitstreamBuffer* bitstream_buffer) override;
void RequestBitrateChange(uint32_t bitrate) override;
void Close() override;
// PluginResource implementation.
void OnReplyReceived(const ResourceMessageReplyParams& params,
const IPC::Message& msg) override;
// Message handlers for the host's messages.
void OnPluginMsgGetSupportedProfilesReply(
const PP_ArrayOutput& output,
const ResourceMessageReplyParams& params,
const std::vector<PP_AudioProfileDescription>& profiles);
void OnPluginMsgInitializeReply(const ResourceMessageReplyParams& params,
int32_t number_of_samples,
int32_t audio_buffer_count,
int32_t audio_buffer_size,
int32_t bitstream_buffer_count,
int32_t bitstream_buffer_size);
void OnPluginMsgEncodeReply(const ResourceMessageReplyParams& params,
int32_t buffer_id);
void OnPluginMsgBitstreamBufferReady(const ResourceMessageReplyParams& params,
int32_t buffer_id);
void OnPluginMsgNotifyError(const ResourceMessageReplyParams& params,
int32_t error);
// Internal utility functions.
void NotifyError(int32_t error);
void TryGetAudioBuffer();
void TryWriteBitstreamBuffer();
void ReleaseBuffers();
int32_t encoder_last_error_;
bool initialized_;
uint32_t number_of_samples_;
using AudioBufferMap =
std::map<PP_Resource, scoped_refptr<AudioBufferResource>>;
AudioBufferMap audio_buffers_;
scoped_refptr<TrackedCallback> get_supported_profiles_callback_;
scoped_refptr<TrackedCallback> initialize_callback_;
scoped_refptr<TrackedCallback> get_buffer_callback_;
PP_Resource* get_buffer_data_;
using EncodeMap = std::map<int32_t, scoped_refptr<TrackedCallback>>;
EncodeMap encode_callbacks_;
scoped_refptr<TrackedCallback> get_bitstream_buffer_callback_;
PP_AudioBitstreamBuffer* get_bitstream_buffer_data_;
MediaStreamBufferManager audio_buffer_manager_;
MediaStreamBufferManager bitstream_buffer_manager_;
// Map of bitstream buffer pointers to buffer ids.
using BufferMap = std::map<void*, int32_t>;
BufferMap bitstream_buffer_map_;
DISALLOW_COPY_AND_ASSIGN(AudioEncoderResource);
};
} // namespace proxy
} // namespace ppapi
#endif // PPAPI_PROXY_AUDIO_ENCODER_RESOURCE_H_

@ -33,7 +33,6 @@
#include "ppapi/c/ppb_audio.h"
#include "ppapi/c/ppb_audio_buffer.h"
#include "ppapi/c/ppb_audio_config.h"
#include "ppapi/c/ppb_audio_encoder.h"
#include "ppapi/c/ppb_console.h"
#include "ppapi/c/ppb_core.h"
#include "ppapi/c/ppb_file_io.h"

@ -135,7 +135,6 @@ IPC_ENUM_TRAITS_MIN_MAX_VALUE(PP_VideoDecoder_Profile,
PP_VIDEODECODER_PROFILE_LAST)
IPC_ENUM_TRAITS_MAX_VALUE(PP_VideoFrame_Format, PP_VIDEOFRAME_FORMAT_LAST)
IPC_ENUM_TRAITS_MAX_VALUE(PP_HardwareAcceleration, PP_HARDWAREACCELERATION_LAST)
IPC_ENUM_TRAITS_MAX_VALUE(PP_AudioProfile, PP_AUDIOPROFILE_MAX)
IPC_ENUM_TRAITS_MAX_VALUE(PP_VideoProfile, PP_VIDEOPROFILE_MAX)
IPC_ENUM_TRAITS_MAX_VALUE(PP_PrivateDirection, PP_PRIVATEDIRECTION_LAST)
IPC_ENUM_TRAITS_MAX_VALUE(PP_TextRenderingMode, PP_TEXTRENDERINGMODE_LAST)
@ -582,14 +581,6 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::PpapiNaClPluginArgs)
IPC_STRUCT_TRAITS_MEMBER(switch_values)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(PP_AudioProfileDescription)
IPC_STRUCT_TRAITS_MEMBER(profile)
IPC_STRUCT_TRAITS_MEMBER(max_channels)
IPC_STRUCT_TRAITS_MEMBER(sample_size)
IPC_STRUCT_TRAITS_MEMBER(sample_rate)
IPC_STRUCT_TRAITS_MEMBER(hardware_accelerated)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(PP_VideoProfileDescription)
IPC_STRUCT_TRAITS_MEMBER(profile)
IPC_STRUCT_TRAITS_MEMBER(max_resolution)
@ -598,15 +589,6 @@ IPC_STRUCT_TRAITS_MEMBER(max_framerate_denominator)
IPC_STRUCT_TRAITS_MEMBER(hardware_accelerated)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(ppapi::proxy::PPB_AudioEncodeParameters)
IPC_STRUCT_TRAITS_MEMBER(channels)
IPC_STRUCT_TRAITS_MEMBER(input_sample_rate)
IPC_STRUCT_TRAITS_MEMBER(input_sample_size)
IPC_STRUCT_TRAITS_MEMBER(output_profile)
IPC_STRUCT_TRAITS_MEMBER(initial_bitrate)
IPC_STRUCT_TRAITS_MEMBER(acceleration)
IPC_STRUCT_TRAITS_END()
// These are from the browser to the plugin.
// Loads the given plugin.
IPC_MESSAGE_CONTROL2(PpapiMsg_LoadPlugin,
@ -1073,32 +1055,6 @@ IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBAudio_StartOrStop,
ppapi::HostResource /* audio_id */,
bool /* play */)
// PPB_AudioEncoder
IPC_MESSAGE_CONTROL0(PpapiHostMsg_AudioEncoder_Create)
IPC_MESSAGE_CONTROL0(PpapiHostMsg_AudioEncoder_GetSupportedProfiles)
IPC_MESSAGE_CONTROL1(PpapiPluginMsg_AudioEncoder_GetSupportedProfilesReply,
std::vector<PP_AudioProfileDescription> /* results */)
IPC_MESSAGE_CONTROL1(PpapiHostMsg_AudioEncoder_Initialize,
ppapi::proxy::PPB_AudioEncodeParameters /* parameters */)
IPC_MESSAGE_CONTROL5(PpapiPluginMsg_AudioEncoder_InitializeReply,
int32_t /* number_of_samples */,
int32_t /* audio_buffer_count */,
int32_t /* audio_buffer_size */,
int32_t /* bitstream_buffer_count */,
int32_t /* bitstream_buffer_size */)
IPC_MESSAGE_CONTROL1(PpapiHostMsg_AudioEncoder_Encode, int32_t /* buffer_id */)
IPC_MESSAGE_CONTROL1(PpapiPluginMsg_AudioEncoder_EncodeReply,
int32_t /* buffer_id */)
IPC_MESSAGE_CONTROL1(PpapiPluginMsg_AudioEncoder_BitstreamBufferReady,
int32_t /* buffer_id */)
IPC_MESSAGE_CONTROL1(PpapiHostMsg_AudioEncoder_RecycleBitstreamBuffer,
int32_t /* buffer_id */)
IPC_MESSAGE_CONTROL1(PpapiHostMsg_AudioEncoder_RequestBitrateChange,
uint32_t /* bitrate */)
IPC_MESSAGE_CONTROL1(PpapiPluginMsg_AudioEncoder_NotifyError,
int32_t /* error */)
IPC_MESSAGE_CONTROL0(PpapiHostMsg_AudioEncoder_Close)
// PPB_Core.
IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBCore_AddRefResource,
ppapi::HostResource)

@ -7,7 +7,6 @@
#include "build/build_config.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/pp_size.h"
#include "ppapi/proxy/audio_encoder_resource.h"
#include "ppapi/proxy/audio_input_resource.h"
#include "ppapi/proxy/audio_output_resource.h"
#include "ppapi/proxy/camera_device_resource.h"
@ -195,10 +194,6 @@ PP_Resource ResourceCreationProxy::CreateAudio(
instance, config_id, AudioCallbackCombined(audio_callback), user_data);
}
PP_Resource ResourceCreationProxy::CreateAudioEncoder(PP_Instance instance) {
return (new AudioEncoderResource(GetConnection(), instance))->GetReference();
}
PP_Resource ResourceCreationProxy::CreateAudioTrusted(PP_Instance instance) {
// Proxied plugins can't create trusted audio devices.
return 0;

@ -99,7 +99,6 @@ class ResourceCreationProxy : public InterfaceProxy,
PP_Resource config_id,
PPB_Audio_Callback audio_callback,
void* user_data) override;
PP_Resource CreateAudioEncoder(PP_Instance instance) override;
PP_Resource CreateAudioTrusted(PP_Instance instance) override;
PP_Resource CreateAudioConfig(PP_Instance instance,
PP_AudioSampleRate sample_rate,

@ -91,15 +91,6 @@ struct PPBURLLoader_UpdateProgress_Params {
int64_t total_bytes_to_be_received;
};
struct PPB_AudioEncodeParameters {
uint32_t channels;
uint32_t input_sample_rate;
uint32_t input_sample_size;
PP_AudioProfile output_profile;
uint32_t initial_bitrate;
PP_HardwareAcceleration acceleration;
};
} // namespace proxy
} // namespace ppapi

@ -22,7 +22,6 @@
F(PPB_Audio_API) \
F(PPB_AudioBuffer_API) \
F(PPB_AudioConfig_API) \
F(PPB_AudioEncoder_API) \
F(PPB_AudioInput_API) \
F(PPB_AudioOutput_API) \
F(PPB_AudioTrusted_API) \

@ -1,143 +0,0 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ppapi/tests/test_audio_encoder.h"
#include "ppapi/c/pp_codecs.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/cpp/audio_encoder.h"
#include "ppapi/tests/testing_instance.h"
REGISTER_TEST_CASE(AudioEncoder);
bool TestAudioEncoder::Init() {
audio_encoder_interface_ = static_cast<const PPB_AudioEncoder_0_1*>(
pp::Module::Get()->GetBrowserInterface(PPB_AUDIOENCODER_INTERFACE_0_1));
return audio_encoder_interface_ && CheckTestingInterface();
}
void TestAudioEncoder::RunTests(const std::string& filter) {
RUN_CALLBACK_TEST(TestAudioEncoder, AvailableCodecs, filter);
RUN_CALLBACK_TEST(TestAudioEncoder, IncorrectParametersFails, filter);
RUN_CALLBACK_TEST(TestAudioEncoder, InitializeTwiceFails, filter);
RUN_CALLBACK_TEST(TestAudioEncoder, InitializeOpusMono, filter);
RUN_CALLBACK_TEST(TestAudioEncoder, InitializeOpusStereo, filter);
}
std::string TestAudioEncoder::TestAvailableCodecs() {
// Test that we get results for supported formats. We should at
// least get the software supported formats.
pp::AudioEncoder audio_encoder(instance_);
ASSERT_FALSE(audio_encoder.is_null());
TestCompletionCallbackWithOutput<std::vector<PP_AudioProfileDescription> >
callback(instance_->pp_instance(), false);
callback.WaitForResult(
audio_encoder.GetSupportedProfiles(callback.GetCallback()));
ASSERT_GE(callback.result(), 1U);
const std::vector<PP_AudioProfileDescription> audio_profiles =
callback.output();
ASSERT_GE(audio_profiles.size(), 1U);
bool found_opus_48hz = false;
for (uint32_t i = 0; i < audio_profiles.size(); ++i) {
const PP_AudioProfileDescription& description = audio_profiles[i];
if (description.profile == PP_AUDIOPROFILE_OPUS &&
description.sample_rate == PP_AUDIOBUFFER_SAMPLERATE_48000 &&
description.max_channels >= 2)
found_opus_48hz = true;
}
ASSERT_TRUE(found_opus_48hz);
PASS();
}
std::string TestAudioEncoder::TestIncorrectParametersFails() {
// Test that initializing the encoder with incorrect size fails.
pp::AudioEncoder audio_encoder(instance_);
ASSERT_FALSE(audio_encoder.is_null());
// Invalid number of channels.
TestCompletionCallback callback(instance_->pp_instance(), false);
callback.WaitForResult(audio_encoder.Initialize(
42, PP_AUDIOBUFFER_SAMPLERATE_48000, PP_AUDIOBUFFER_SAMPLESIZE_16_BITS,
PP_AUDIOPROFILE_OPUS, 10000, PP_HARDWAREACCELERATION_WITHFALLBACK,
callback.GetCallback()));
ASSERT_EQ(PP_ERROR_NOTSUPPORTED, callback.result());
// Invalid sampling rate.
callback.WaitForResult(audio_encoder.Initialize(
2, static_cast<PP_AudioBuffer_SampleRate>(123456),
PP_AUDIOBUFFER_SAMPLESIZE_16_BITS, PP_AUDIOPROFILE_OPUS, 10000,
PP_HARDWAREACCELERATION_WITHFALLBACK, callback.GetCallback()));
ASSERT_EQ(PP_ERROR_NOTSUPPORTED, callback.result());
// Invalid sample size.
callback.WaitForResult(audio_encoder.Initialize(
2, static_cast<PP_AudioBuffer_SampleRate>(48000),
static_cast<PP_AudioBuffer_SampleSize>(72), PP_AUDIOPROFILE_OPUS, 10000,
PP_HARDWAREACCELERATION_WITHFALLBACK, callback.GetCallback()));
ASSERT_EQ(PP_ERROR_NOTSUPPORTED, callback.result());
PASS();
}
std::string TestAudioEncoder::TestInitializeTwiceFails() {
// Test that initializing the encoder with incorrect size fails.
pp::AudioEncoder audio_encoder(instance_);
ASSERT_FALSE(audio_encoder.is_null());
TestCompletionCallback callback(instance_->pp_instance(), false);
callback.WaitForResult(audio_encoder.Initialize(
2, PP_AUDIOBUFFER_SAMPLERATE_48000, PP_AUDIOBUFFER_SAMPLESIZE_16_BITS,
PP_AUDIOPROFILE_OPUS, 10000, PP_HARDWAREACCELERATION_WITHFALLBACK,
callback.GetCallback()));
ASSERT_EQ(PP_OK, callback.result());
callback.WaitForResult(audio_encoder.Initialize(
2, PP_AUDIOBUFFER_SAMPLERATE_48000, PP_AUDIOBUFFER_SAMPLESIZE_16_BITS,
PP_AUDIOPROFILE_OPUS, 10000, PP_HARDWAREACCELERATION_WITHFALLBACK,
callback.GetCallback()));
ASSERT_EQ(PP_ERROR_FAILED, callback.result());
PASS();
}
std::string TestAudioEncoder::TestInitializeOpusMono() {
return TestInitializeCodec(1, PP_AUDIOBUFFER_SAMPLERATE_48000,
PP_AUDIOBUFFER_SAMPLESIZE_16_BITS,
PP_AUDIOPROFILE_OPUS);
}
std::string TestAudioEncoder::TestInitializeOpusStereo() {
return TestInitializeCodec(2, PP_AUDIOBUFFER_SAMPLERATE_48000,
PP_AUDIOBUFFER_SAMPLESIZE_16_BITS,
PP_AUDIOPROFILE_OPUS);
}
std::string TestAudioEncoder::TestInitializeCodec(
uint32_t channels,
PP_AudioBuffer_SampleRate input_sample_rate,
PP_AudioBuffer_SampleSize input_sample_size,
PP_AudioProfile output_profile) {
pp::AudioEncoder audio_encoder(instance_);
ASSERT_FALSE(audio_encoder.is_null());
pp::Size audio_size(640, 480);
TestCompletionCallback callback(instance_->pp_instance(), false);
callback.WaitForResult(audio_encoder.Initialize(
channels, input_sample_rate, input_sample_size, output_profile, 10000,
PP_HARDWAREACCELERATION_WITHFALLBACK, callback.GetCallback()));
ASSERT_EQ(PP_OK, callback.result());
ASSERT_GE(audio_encoder.GetNumberOfSamples(), 2U);
TestCompletionCallbackWithOutput<pp::AudioBuffer> get_buffer(
instance_->pp_instance(), false);
get_buffer.WaitForResult(audio_encoder.GetBuffer(get_buffer.GetCallback()));
ASSERT_EQ(PP_OK, get_buffer.result());
PASS();
}

@ -1,38 +0,0 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PPAPI_TESTS_TEST_AUDIO_ENCODER_H_
#define PPAPI_TESTS_TEST_AUDIO_ENCODER_H_
#include <string>
#include "ppapi/c/pp_stdint.h"
#include "ppapi/c/ppb_audio_encoder.h"
#include "ppapi/tests/test_case.h"
class TestAudioEncoder : public TestCase {
public:
explicit TestAudioEncoder(TestingInstance* instance) : TestCase(instance) {}
private:
// TestCase implementation.
virtual bool Init();
virtual void RunTests(const std::string& filter);
std::string TestAvailableCodecs();
std::string TestIncorrectParametersFails();
std::string TestInitializeTwiceFails();
std::string TestInitializeOpusMono();
std::string TestInitializeOpusStereo();
std::string TestInitializeCodec(uint32_t channels,
PP_AudioBuffer_SampleRate input_sample_rate,
PP_AudioBuffer_SampleSize input_sample_size,
PP_AudioProfile output_profile);
// Used by the tests that access the C API directly.
const PPB_AudioEncoder_0_1* audio_encoder_interface_;
};
#endif // PPAPI_TESTS_TEST_AUDIO_ENCODER_H_

@ -28,8 +28,6 @@ source_set("thunk") {
"ppb_audio_buffer_thunk.cc",
"ppb_audio_config_api.h",
"ppb_audio_config_thunk.cc",
"ppb_audio_encoder_api.h",
"ppb_audio_encoder_thunk.cc",
"ppb_audio_input_api.h",
"ppb_audio_output_api.h",
"ppb_audio_thunk.cc",

@ -10,7 +10,6 @@
#include "ppapi/thunk/interfaces_preamble.h"
// Interfaces go here.
PROXIED_IFACE(PPB_AUDIOENCODER_INTERFACE_0_1, PPB_AudioEncoder_0_1)
PROXIED_IFACE(PPB_VIDEODECODER_INTERFACE_0_1, PPB_VideoDecoder_0_1)
PROXIED_IFACE(PPB_VIDEOENCODER_INTERFACE_0_1, PPB_VideoEncoder_0_1)
PROXIED_IFACE(PPB_VPNPROVIDER_INTERFACE_0_1, PPB_VpnProvider_0_1)

@ -1,48 +0,0 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PPAPI_THUNK_AUDIO_ENCODER_API_H_
#define PPAPI_THUNK_AUDIO_ENCODER_API_H_
#include <stdint.h>
#include "ppapi/c/ppb_audio_encoder.h"
#include "ppapi/thunk/ppapi_thunk_export.h"
namespace ppapi {
namespace thunk {
class PPAPI_THUNK_EXPORT PPB_AudioEncoder_API {
public:
virtual ~PPB_AudioEncoder_API() {}
virtual int32_t GetSupportedProfiles(
const PP_ArrayOutput& output,
const scoped_refptr<TrackedCallback>& callback) = 0;
virtual int32_t Initialize(
uint32_t channels,
PP_AudioBuffer_SampleRate input_sample_rate,
PP_AudioBuffer_SampleSize input_sample_size,
PP_AudioProfile output_profile,
uint32_t initial_bitrate,
PP_HardwareAcceleration acceleration,
const scoped_refptr<TrackedCallback>& callback) = 0;
virtual int32_t GetNumberOfSamples() = 0;
virtual int32_t GetBuffer(PP_Resource* audio_buffer,
const scoped_refptr<TrackedCallback>& callback) = 0;
virtual int32_t Encode(PP_Resource audio_buffer,
const scoped_refptr<TrackedCallback>& callback) = 0;
virtual int32_t GetBitstreamBuffer(
PP_AudioBitstreamBuffer* bitstream_buffer,
const scoped_refptr<TrackedCallback>& callback) = 0;
virtual void RecycleBitstreamBuffer(
const PP_AudioBitstreamBuffer* bitstream_buffer) = 0;
virtual void RequestBitrateChange(uint32_t bitrate) = 0;
virtual void Close() = 0;
};
} // namespace thunk
} // namespace ppapi
#endif // PPAPI_THUNK_AUDIO_ENCODER_API_H_

@ -122,7 +122,6 @@ class ResourceCreationAPI {
PP_Resource config_id,
PPB_Audio_Callback audio_callback,
void* user_data) = 0;
virtual PP_Resource CreateAudioEncoder(PP_Instance instance) = 0;
virtual PP_Resource CreateAudioTrusted(PP_Instance instance) = 0;
virtual PP_Resource CreateAudioConfig(PP_Instance instance,
PP_AudioSampleRate sample_rate,

@ -57143,7 +57143,7 @@ Called by update_net_trust_anchors.py.-->
<int value="1519132417" label="PPB_FileSystem;1.0"/>
<int value="1520420939" label="PPB_MouseCursor;1.0"/>
<int value="1528832860" label="PPB_FileChooser(Dev);0.6"/>
<int value="1534600005" label="PPB_AudioEncoder;0.1"/>
<int value="1534600005" label="PPB_AudioEncoder;0.1(Removed)"/>
<int value="1577776196" label="PPB_InputEvent_Private;0.1"/>
<int value="1616589391" label="PPB_TCPServerSocket_Private;0.2"/>
<int value="1641037564" label="PPB_VideoSource_Private;0.1"/>