diff options
31 files changed, 1271 insertions, 7 deletions
diff --git a/chrome/common/ppapi_utils.cc b/chrome/common/ppapi_utils.cc index 0d8aac1..3eed1c6 100644 --- a/chrome/common/ppapi_utils.cc +++ b/chrome/common/ppapi_utils.cc @@ -30,6 +30,7 @@ #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_compositor.h" #include "ppapi/c/ppb_compositor_layer.h" #include "ppapi/c/ppb_console.h" diff --git a/content/renderer/pepper/plugin_module.cc b/content/renderer/pepper/plugin_module.cc index a708d4a..223b848 100644 --- a/content/renderer/pepper/plugin_module.cc +++ b/content/renderer/pepper/plugin_module.cc @@ -54,6 +54,7 @@ #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_compositor.h" #include "ppapi/c/ppb_compositor_layer.h" #include "ppapi/c/ppb_console.h" diff --git a/content/renderer/pepper/resource_creation_impl.cc b/content/renderer/pepper/resource_creation_impl.cc index 7ffc70c..d23c002 100644 --- a/content/renderer/pepper/resource_creation_impl.cc +++ b/content/renderer/pepper/resource_creation_impl.cc @@ -64,6 +64,10 @@ 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. } diff --git a/content/renderer/pepper/resource_creation_impl.h b/content/renderer/pepper/resource_creation_impl.h index 297bda9..9523082 100644 --- a/content/renderer/pepper/resource_creation_impl.h +++ b/content/renderer/pepper/resource_creation_impl.h @@ -31,6 +31,7 @@ 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, diff --git a/native_client_sdk/src/libraries/ppapi/library.dsc b/native_client_sdk/src/libraries/ppapi/library.dsc index ca01668..74c6677 100644 --- a/native_client_sdk/src/libraries/ppapi/library.dsc +++ b/native_client_sdk/src/libraries/ppapi/library.dsc @@ -21,6 +21,7 @@ 'pp_array_output.h', 'ppb_audio_buffer.h', 'ppb_audio_config.h', + 'ppb_audio_encoder.h', 'ppb_audio.h', 'ppb_compositor.h', 'ppb_compositor_layer.h', diff --git a/native_client_sdk/src/libraries/ppapi_cpp/library.dsc b/native_client_sdk/src/libraries/ppapi_cpp/library.dsc index 32400ff..2b0c6e5 100644 --- a/native_client_sdk/src/libraries/ppapi_cpp/library.dsc +++ b/native_client_sdk/src/libraries/ppapi_cpp/library.dsc @@ -17,6 +17,7 @@ 'audio.cc', 'audio_buffer.cc', 'audio_config.cc', + 'audio_encoder.cc', 'compositor.cc', 'compositor_layer.cc', 'core.cc', @@ -91,6 +92,7 @@ 'array_output.h', 'audio_buffer.h', 'audio_config.h', + 'audio_encoder.h', 'audio.h', 'completion_callback.h', 'compositor.h', diff --git a/ppapi/api/pp_codecs.idl b/ppapi/api/pp_codecs.idl index 89642a9..2bf47af 100644 --- a/ppapi/api/pp_codecs.idl +++ b/ppapi/api/pp_codecs.idl @@ -24,6 +24,15 @@ enum PP_VideoProfile { }; /** + * Audio profiles. + */ +enum PP_AudioProfile { + PP_AUDIOPROFILE_OPUS = 0, + PP_AUDIOPROFILE_SPEEX = 1, + PP_AUDIOPROFILE_MAX = PP_AUDIOPROFILE_SPEEX +}; + +/** * Hardware acceleration options. */ enum PP_HardwareAcceleration { @@ -180,6 +189,37 @@ struct PP_VideoProfileDescription_0_1 { }; /** + * 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. */ struct PP_BitstreamBuffer { @@ -198,3 +238,18 @@ struct PP_BitstreamBuffer { */ PP_Bool key_frame; }; + +/** + * Struct describing an audio bitstream buffer. + */ +struct PP_AudioBitstreamBuffer { + /** + * The size, in bytes, of the bitstream data. + */ + uint32_t size; + + /** + * The base address of the bitstream data. + */ + mem_t buffer; +}; diff --git a/ppapi/api/ppb_audio_encoder.idl b/ppapi/api/ppb_audio_encoder.idl new file mode 100644 index 0000000..0a8029f --- /dev/null +++ b/ppapi/api/ppb_audio_encoder.idl @@ -0,0 +1,209 @@ +/* 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); +}; diff --git a/ppapi/c/pp_codecs.h b/ppapi/c/pp_codecs.h index 173f9f4..e897799 100644 --- a/ppapi/c/pp_codecs.h +++ b/ppapi/c/pp_codecs.h @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -/* From pp_codecs.idl modified Fri Apr 17 10:55:27 2015. */ +/* From pp_codecs.idl modified Thu May 21 15:11:01 2015. */ #ifndef PPAPI_C_PP_CODECS_H_ #define PPAPI_C_PP_CODECS_H_ @@ -43,6 +43,15 @@ typedef enum { } PP_VideoProfile; /** + * Audio profiles. + */ +typedef enum { + PP_AUDIOPROFILE_OPUS = 0, + PP_AUDIOPROFILE_SPEEX = 1, + PP_AUDIOPROFILE_MAX = PP_AUDIOPROFILE_SPEEX +} PP_AudioProfile; + +/** * Hardware acceleration options. */ typedef enum { @@ -188,6 +197,33 @@ struct PP_VideoProfileDescription_0_1 { }; /** + * 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. */ struct PP_BitstreamBuffer { @@ -204,6 +240,20 @@ struct PP_BitstreamBuffer { */ PP_Bool key_frame; }; + +/** + * Struct describing an audio bitstream buffer. + */ +struct PP_AudioBitstreamBuffer { + /** + * The size, in bytes, of the bitstream data. + */ + uint32_t size; + /** + * The base address of the bitstream data. + */ + void* buffer; +}; /** * @} */ diff --git a/ppapi/c/pp_macros.h b/ppapi/c/pp_macros.h index f92a363..47337cb 100644 --- a/ppapi/c/pp_macros.h +++ b/ppapi/c/pp_macros.h @@ -9,7 +9,7 @@ #define PPAPI_C_PP_MACROS_H_ -#define PPAPI_RELEASE 46 +#define PPAPI_RELEASE 47 /** * @file diff --git a/ppapi/c/ppb_audio_encoder.h b/ppapi/c/ppb_audio_encoder.h new file mode 100644 index 0000000..7fdac90 --- /dev/null +++ b/ppapi/c/ppb_audio_encoder.h @@ -0,0 +1,222 @@ +/* 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_ */ + diff --git a/ppapi/cpp/audio_encoder.cc b/ppapi/cpp/audio_encoder.cc new file mode 100644 index 0000000..bea733b --- /dev/null +++ b/ppapi/cpp/audio_encoder.cc @@ -0,0 +1,118 @@ +// 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 diff --git a/ppapi/cpp/audio_encoder.h b/ppapi/cpp/audio_encoder.h new file mode 100644 index 0000000..620d507 --- /dev/null +++ b/ppapi/cpp/audio_encoder.h @@ -0,0 +1,162 @@ +// 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 "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_ diff --git a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c index 07ba3fc..e00bc30 100644 --- a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c +++ b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c @@ -17,6 +17,7 @@ #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_compositor.h" #include "ppapi/c/ppb_compositor_layer.h" #include "ppapi/c/ppb_console.h" @@ -93,6 +94,7 @@ 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_Compositor_0_1; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_CompositorLayer_0_1; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_CompositorLayer_0_2; @@ -216,6 +218,65 @@ 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_Compositor_0_1 */ static PP_Bool Pnacl_M37_PPB_Compositor_IsCompositor(PP_Resource resource) { @@ -3730,8 +3791,6 @@ static PP_Bool Pnacl_M19_PPB_HostResolver_Private_GetNetAddress(PP_Resource host /* End wrapper methods for PPB_HostResolver_Private_0_1 */ -/* Not generating wrapper methods for PPB_InputEvent_Private_0_1 */ - /* Begin wrapper methods for PPB_Instance_Private_0_1 */ static void Pnacl_M13_PPB_Instance_Private_GetWindowObject(struct PP_Var* _struct_result, PP_Instance instance) { @@ -4615,6 +4674,20 @@ 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_Compositor_0_1 Pnacl_Wrappers_PPB_Compositor_0_1 = { .IsCompositor = (PP_Bool (*)(PP_Resource resource))&Pnacl_M37_PPB_Compositor_IsCompositor, .Create = (PP_Resource (*)(PP_Instance instance))&Pnacl_M37_PPB_Compositor_Create, @@ -5598,8 +5671,6 @@ static const struct PPB_HostResolver_Private_0_1 Pnacl_Wrappers_PPB_HostResolver .GetNetAddress = (PP_Bool (*)(PP_Resource host_resolver, uint32_t index, struct PP_NetAddress_Private* addr))&Pnacl_M19_PPB_HostResolver_Private_GetNetAddress }; -/* Not generating wrapper interface for PPB_InputEvent_Private_0_1 */ - static const struct PPB_Instance_Private_0_1 Pnacl_Wrappers_PPB_Instance_Private_0_1 = { .GetWindowObject = (struct PP_Var (*)(PP_Instance instance))&Pnacl_M13_PPB_Instance_Private_GetWindowObject, .GetOwnerElementObject = (struct PP_Var (*)(PP_Instance instance))&Pnacl_M13_PPB_Instance_Private_GetOwnerElementObject, @@ -5825,6 +5896,12 @@ 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_Compositor_0_1 = { .iface_macro = PPB_COMPOSITOR_INTERFACE_0_1, .wrapped_iface = (const void *) &Pnacl_Wrappers_PPB_Compositor_0_1, @@ -6492,6 +6569,7 @@ 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_Compositor_0_1, &Pnacl_WrapperInfo_PPB_CompositorLayer_0_1, &Pnacl_WrapperInfo_PPB_CompositorLayer_0_2, diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi index eccb91e..f220436 100644 --- a/ppapi/ppapi_proxy.gypi +++ b/ppapi/ppapi_proxy.gypi @@ -21,6 +21,8 @@ 'proxy/audio_buffer_resource.cc', 'proxy/audio_buffer_resource.h', + 'proxy/audio_encoder_resource.cc', + 'proxy/audio_encoder_resource.h', 'proxy/audio_input_resource.cc', 'proxy/audio_input_resource.h', 'proxy/broker_dispatcher.cc', diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index 5dd97ab..2b5f59e 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -145,6 +145,8 @@ 'thunk/ppb_audio_buffer_thunk.cc', 'thunk/ppb_audio_config_api.h', 'thunk/ppb_audio_config_thunk.cc', + 'thunk/ppb_audio_encoder_api.h', + 'thunk/ppb_audio_encoder_thunk.cc', 'thunk/ppb_audio_input_api.h', 'thunk/ppb_audio_input_dev_thunk.cc', 'thunk/ppb_audio_thunk.cc', diff --git a/ppapi/ppapi_sources.gypi b/ppapi/ppapi_sources.gypi index c27ad183..55e1ff2 100644 --- a/ppapi/ppapi_sources.gypi +++ b/ppapi/ppapi_sources.gypi @@ -28,6 +28,7 @@ 'c/ppb_audio.h', 'c/ppb_audio_buffer.h', 'c/ppb_audio_config.h', + 'c/ppb_audio_encoder.h', 'c/ppb_compositor.h', 'c/ppb_console.h', 'c/ppb_core.h', @@ -64,6 +65,7 @@ 'c/ppb_var_array_buffer.h', 'c/ppb_var_dictionary.h', 'c/ppb_video_decoder.h', + 'c/ppb_video_encoder.h', 'c/ppb_video_frame.h', 'c/ppb_view.h', 'c/ppb_websocket.h', @@ -151,6 +153,8 @@ 'cpp/audio_buffer.h', 'cpp/audio_config.cc', 'cpp/audio_config.h', + 'cpp/audio_encoder.cc', + 'cpp/audio_encoder.h', 'cpp/completion_callback.h', 'cpp/compositor.cc', 'cpp/compositor.h', diff --git a/ppapi/proxy/BUILD.gn b/ppapi/proxy/BUILD.gn index ffec0db..e3bd8c5 100644 --- a/ppapi/proxy/BUILD.gn +++ b/ppapi/proxy/BUILD.gn @@ -19,6 +19,8 @@ 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", diff --git a/ppapi/proxy/audio_encoder_resource.cc b/ppapi/proxy/audio_encoder_resource.cc new file mode 100644 index 0000000..d1576fb --- /dev/null +++ b/ppapi/proxy/audio_encoder_resource.cc @@ -0,0 +1,72 @@ +// 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/proxy/audio_encoder_resource.h" + +namespace ppapi { +namespace proxy { + +AudioEncoderResource::AudioEncoderResource(Connection connection, + PP_Instance instance) + : PluginResource(connection, instance) { +} + +AudioEncoderResource::~AudioEncoderResource() { +} + +thunk::PPB_AudioEncoder_API* AudioEncoderResource::AsPPB_AudioEncoder_API() { + return this; +} + +int32_t AudioEncoderResource::GetSupportedProfiles( + const PP_ArrayOutput& output, + const scoped_refptr<TrackedCallback>& callback) { + return PP_ERROR_NOTSUPPORTED; +} + +int32_t AudioEncoderResource::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) { + return PP_ERROR_NOTSUPPORTED; +} + +int32_t AudioEncoderResource::GetNumberOfSamples() { + return PP_ERROR_NOTSUPPORTED; +} + +int32_t AudioEncoderResource::GetBuffer( + PP_Resource* audio_buffer, + const scoped_refptr<TrackedCallback>& callback) { + return PP_ERROR_NOTSUPPORTED; +} + +int32_t AudioEncoderResource::Encode( + PP_Resource audio_buffer, + const scoped_refptr<TrackedCallback>& callback) { + return PP_ERROR_NOTSUPPORTED; +} + +int32_t AudioEncoderResource::GetBitstreamBuffer( + PP_AudioBitstreamBuffer* bitstream_buffer, + const scoped_refptr<TrackedCallback>& callback) { + return PP_ERROR_NOTSUPPORTED; +} + +void AudioEncoderResource::RecycleBitstreamBuffer( + const PP_AudioBitstreamBuffer* bitstream_buffer) { +} + +void AudioEncoderResource::RequestBitrateChange(uint32_t bitrate) { +} + +void AudioEncoderResource::Close() { +} + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/audio_encoder_resource.h b/ppapi/proxy/audio_encoder_resource.h new file mode 100644 index 0000000..23fcee2 --- /dev/null +++ b/ppapi/proxy/audio_encoder_resource.h @@ -0,0 +1,66 @@ +// 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 "base/basictypes.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/scoped_vector.h" +#include "ppapi/proxy/connection.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/shared_impl/resource.h" +#include "ppapi/thunk/ppb_audio_encoder_api.h" + +namespace ppapi { + +class TrackedCallback; + +namespace proxy { + +class SerializedHandle; +class VideoFrameResource; + +class PPAPI_PROXY_EXPORT AudioEncoderResource + : public PluginResource, + public thunk::PPB_AudioEncoder_API { + public: + AudioEncoderResource(Connection connection, PP_Instance instance); + ~AudioEncoderResource() override; + + thunk::PPB_AudioEncoder_API* AsPPB_AudioEncoder_API() override; + + private: + // PPB_AduioEncoder_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; + + DISALLOW_COPY_AND_ASSIGN(AudioEncoderResource); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_AUDIO_ENCODER_RESOURCE_H_ diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc index f5e3e8f..db7a67a 100644 --- a/ppapi/proxy/interface_list.cc +++ b/ppapi/proxy/interface_list.cc @@ -29,6 +29,7 @@ #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_compositor.h" #include "ppapi/c/ppb_compositor_layer.h" #include "ppapi/c/ppb_console.h" diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index aa522ee..a9d3afc 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -6,6 +6,7 @@ #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/camera_device_resource.h" #include "ppapi/proxy/compositor_resource.h" @@ -208,6 +209,10 @@ 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; diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h index 4aa3d43..f2bed99 100644 --- a/ppapi/proxy/resource_creation_proxy.h +++ b/ppapi/proxy/resource_creation_proxy.h @@ -101,6 +101,7 @@ 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, diff --git a/ppapi/shared_impl/resource.h b/ppapi/shared_impl/resource.h index 21c62de..025ea3b 100644 --- a/ppapi/shared_impl/resource.h +++ b/ppapi/shared_impl/resource.h @@ -22,6 +22,7 @@ F(PPB_Audio_API) \ F(PPB_AudioBuffer_API) \ F(PPB_AudioConfig_API) \ + F(PPB_AudioEncoder_API) \ F(PPB_AudioInput_API) \ F(PPB_AudioTrusted_API) \ F(PPB_Broker_API) \ diff --git a/ppapi/thunk/BUILD.gn b/ppapi/thunk/BUILD.gn index b4adef9..766dc4a 100644 --- a/ppapi/thunk/BUILD.gn +++ b/ppapi/thunk/BUILD.gn @@ -17,6 +17,8 @@ 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_thunk.cc", "ppb_broker_api.h", diff --git a/ppapi/thunk/interfaces_ppb_public_dev_channel.h b/ppapi/thunk/interfaces_ppb_public_dev_channel.h index 8214dcf..3495282 100644 --- a/ppapi/thunk/interfaces_ppb_public_dev_channel.h +++ b/ppapi/thunk/interfaces_ppb_public_dev_channel.h @@ -8,6 +8,7 @@ #include "ppapi/thunk/interfaces_preamble.h" // Interfaces go here. +PROXIED_IFACE(PPB_AUDIOENCODER_INTERFACE_0_1, PPB_AudioEncoder_0_1) PROXIED_IFACE(PPB_COMPOSITOR_INTERFACE_0_1, PPB_Compositor_0_1) PROXIED_IFACE(PPB_COMPOSITORLAYER_INTERFACE_0_1, PPB_CompositorLayer_0_1) PROXIED_IFACE(PPB_COMPOSITORLAYER_INTERFACE_0_2, PPB_CompositorLayer_0_2) diff --git a/ppapi/thunk/ppb_audio_buffer_thunk.cc b/ppapi/thunk/ppb_audio_buffer_thunk.cc index cafa5c0..178da8e 100644 --- a/ppapi/thunk/ppb_audio_buffer_thunk.cc +++ b/ppapi/thunk/ppb_audio_buffer_thunk.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// From ppb_audio_buffer.idl modified Mon Apr 7 08:56:43 2014. +// From ppb_audio_buffer.idl modified Thu May 15 17:11:43 2014. #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppb_audio_buffer.h" diff --git a/ppapi/thunk/ppb_audio_encoder_api.h b/ppapi/thunk/ppb_audio_encoder_api.h new file mode 100644 index 0000000..68e1378 --- /dev/null +++ b/ppapi/thunk/ppb_audio_encoder_api.h @@ -0,0 +1,46 @@ +// 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 "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_ diff --git a/ppapi/thunk/ppb_audio_encoder_thunk.cc b/ppapi/thunk/ppb_audio_encoder_thunk.cc new file mode 100644 index 0000000..25f8907 --- /dev/null +++ b/ppapi/thunk/ppb_audio_encoder_thunk.cc @@ -0,0 +1,153 @@ +// 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. + +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/ppb_audio_encoder.h" +#include "ppapi/shared_impl/tracked_callback.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppapi_thunk_export.h" +#include "ppapi/thunk/ppb_audio_encoder_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +PP_Resource Create(PP_Instance instance) { + VLOG(4) << "PPB_AudioEncoder::Create()"; + EnterResourceCreation enter(instance); + if (enter.failed()) + return 0; + return enter.functions()->CreateAudioEncoder(instance); +} + +PP_Bool IsAudioEncoder(PP_Resource resource) { + VLOG(4) << "PPB_AudioEncoder::IsAudioEncoder()"; + EnterResource<PPB_AudioEncoder_API> enter(resource, false); + return PP_FromBool(enter.succeeded()); +} + +int32_t GetSupportedProfiles(PP_Resource audio_encoder, + struct PP_ArrayOutput output, + struct PP_CompletionCallback callback) { + VLOG(4) << "PPB_AudioEncoder::GetSupportedProfiles()"; + EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, callback, true); + if (enter.failed()) + return enter.retval(); + return enter.SetResult( + enter.object()->GetSupportedProfiles(output, enter.callback())); +} + +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) { + VLOG(4) << "PPB_AudioEncoder::Initialize()"; + EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, callback, true); + if (enter.failed()) + return enter.retval(); + return enter.SetResult(enter.object()->Initialize(channels, + input_sample_rate, + input_sample_size, + output_profile, + initial_bitrate, + acceleration, + enter.callback())); +} + +int32_t GetNumberOfSamples(PP_Resource audio_encoder) { + VLOG(4) << "PPB_AudioEncoder::GetNumberOfSamples()"; + EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, true); + if (enter.failed()) + return enter.retval(); + return enter.object()->GetNumberOfSamples(); +} + +int32_t GetBuffer(PP_Resource audio_encoder, + PP_Resource* audio_buffer, + struct PP_CompletionCallback callback) { + VLOG(4) << "PPB_AudioEncoder::GetBuffer()"; + EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, callback, true); + if (enter.failed()) + return enter.retval(); + return enter.SetResult( + enter.object()->GetBuffer(audio_buffer, enter.callback())); +} + +int32_t Encode(PP_Resource audio_encoder, + PP_Resource audio_buffer, + struct PP_CompletionCallback callback) { + VLOG(4) << "PPB_AudioEncoder::Encode()"; + EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, callback, true); + if (enter.failed()) + return enter.retval(); + return enter.SetResult( + enter.object()->Encode(audio_buffer, enter.callback())); +} + +int32_t GetBitstreamBuffer(PP_Resource audio_encoder, + struct PP_AudioBitstreamBuffer* bitstream_buffer, + struct PP_CompletionCallback callback) { + VLOG(4) << "PPB_AudioEncoder::GetBitstreamBuffer()"; + EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, callback, true); + if (enter.failed()) + return enter.retval(); + return enter.SetResult( + enter.object()->GetBitstreamBuffer(bitstream_buffer, enter.callback())); +} + +void RecycleBitstreamBuffer( + PP_Resource audio_encoder, + const struct PP_AudioBitstreamBuffer* bitstream_buffer) { + VLOG(4) << "PPB_AudioEncoder::RecycleBitstreamBuffer()"; + EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, true); + if (enter.failed()) + return; + enter.object()->RecycleBitstreamBuffer(bitstream_buffer); +} + +void RequestBitrateChange(PP_Resource audio_encoder, uint32_t bitrate) { + VLOG(4) << "PPB_AudioEncoder::RequestBitrateChange()"; + EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, true); + if (enter.failed()) + return; + enter.object()->RequestBitrateChange(bitrate); +} + +void Close(PP_Resource audio_encoder) { + VLOG(4) << "PPB_AudioEncoder::Close()"; + EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, true); + if (enter.failed()) + return; + enter.object()->Close(); +} + +const PPB_AudioEncoder_0_1 g_ppb_audioencoder_thunk_0_1 = { + &Create, + &IsAudioEncoder, + &GetSupportedProfiles, + &Initialize, + &GetNumberOfSamples, + &GetBuffer, + &Encode, + &GetBitstreamBuffer, + &RecycleBitstreamBuffer, + &RequestBitrateChange, + &Close}; + +} // namespace + +PPAPI_THUNK_EXPORT const PPB_AudioEncoder_0_1* GetPPB_AudioEncoder_0_1_Thunk() { + return &g_ppb_audioencoder_thunk_0_1; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h index 9a813d5..89c5e58 100644 --- a/ppapi/thunk/resource_creation_api.h +++ b/ppapi/thunk/resource_creation_api.h @@ -120,6 +120,7 @@ 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, diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index 3de432e..979f473 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -68196,6 +68196,7 @@ To add a new entry, add it with any value and run test to compute valid value. <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="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"/> |