Commit 764a8c95 authored by lionel.g.landwerlin's avatar lionel.g.landwerlin Committed by Commit bot

ppapi: implement PPB_AudioEncoder

BUG=461222

Review URL: https://codereview.chromium.org/1348563003

Cr-Commit-Position: refs/heads/master@{#360469}
parent ac8f1aac
......@@ -945,6 +945,8 @@ IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
RUN_AUDIO_CONFIG_SUBTESTS;
}
TEST_PPAPI_NACL(AudioEncoder)
// PPB_Audio tests.
#define RUN_AUDIO_SUBTESTS \
RunTestViaHTTP( \
......
......@@ -505,6 +505,8 @@
'renderer/pepper/host_var_tracker.h',
'renderer/pepper/message_channel.cc',
'renderer/pepper/message_channel.h',
'renderer/pepper/pepper_audio_encoder_host.cc',
'renderer/pepper/pepper_audio_encoder_host.h',
'renderer/pepper/pepper_audio_input_host.cc',
'renderer/pepper/pepper_audio_input_host.h',
'renderer/pepper/pepper_broker.cc',
......@@ -898,6 +900,7 @@
'../ppapi/ppapi_internal.gyp:ppapi_host',
'../ppapi/ppapi_internal.gyp:ppapi_proxy',
'../ppapi/ppapi_internal.gyp:ppapi_shared',
'../third_party/opus/opus.gyp:opus',
],
}],
['enable_pepper_cdms != 1', {
......
......@@ -183,6 +183,7 @@ source_set("renderer") {
"//ppapi/proxy",
"//ppapi/shared_impl",
"//third_party/libvpx_new",
"//third_party/opus",
]
}
......
......@@ -8,6 +8,7 @@ include_rules = [
"+media/video",
"+third_party/libvpx_new",
"+third_party/libyuv",
"+third_party/opus",
"+ui/base/ime",
"+ui/base/range",
]
......@@ -9,6 +9,7 @@
#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_camera_device_host.h"
#include "content/renderer/pepper/pepper_compositor_host.h"
......@@ -201,6 +202,9 @@ scoped_ptr<ResourceHost> ContentRendererPepperHostFactory::CreateResourceHost(
// Dev interfaces.
if (GetPermissions().HasPermission(ppapi::PERMISSION_DEV)) {
switch (message.type()) {
case PpapiHostMsg_AudioEncoder_Create::ID:
return scoped_ptr<ResourceHost>(
new PepperAudioEncoderHost(host_, instance, resource));
case PpapiHostMsg_AudioInput_Create::ID:
return scoped_ptr<ResourceHost>(
new PepperAudioInputHost(host_, instance, resource));
......
This diff is collapsed.
// 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 CONTENT_RENDERER_PEPPER_PEPPER_AUDIO_ENCODER_HOST_H_
#define CONTENT_RENDERER_PEPPER_PEPPER_AUDIO_ENCODER_HOST_H_
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/numerics/safe_math.h"
#include "content/common/content_export.h"
#include "ppapi/c/pp_codecs.h"
#include "ppapi/host/host_message_context.h"
#include "ppapi/host/resource_host.h"
#include "ppapi/proxy/resource_message_params.h"
#include "ppapi/proxy/serialized_structs.h"
#include "ppapi/shared_impl/media_stream_buffer_manager.h"
namespace content {
class RendererPpapiHost;
class CONTENT_EXPORT PepperAudioEncoderHost
: public ppapi::host::ResourceHost,
public ppapi::MediaStreamBufferManager::Delegate {
public:
PepperAudioEncoderHost(RendererPpapiHost* host,
PP_Instance instance,
PP_Resource resource);
~PepperAudioEncoderHost() override;
private:
class AudioEncoderImpl;
// ResourceHost implementation.
int32_t OnResourceMessageReceived(
const IPC::Message& msg,
ppapi::host::HostMessageContext* context) override;
int32_t OnHostMsgGetSupportedProfiles(
ppapi::host::HostMessageContext* context);
int32_t OnHostMsgInitialize(
ppapi::host::HostMessageContext* context,
const ppapi::proxy::PPB_AudioEncodeParameters& parameters);
int32_t OnHostMsgGetAudioBuffers(ppapi::host::HostMessageContext* context);
int32_t OnHostMsgEncode(ppapi::host::HostMessageContext* context,
int32_t buffer_id);
int32_t OnHostMsgRecycleBitstreamBuffer(
ppapi::host::HostMessageContext* context,
int32_t buffer_id);
int32_t OnHostMsgRequestBitrateChange(
ppapi::host::HostMessageContext* context,
uint32_t bitrate);
int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context);
void GetSupportedProfiles(std::vector<PP_AudioProfileDescription>* profiles);
bool IsInitializationValid(
const ppapi::proxy::PPB_AudioEncodeParameters& parameters);
bool AllocateBuffers(
const ppapi::proxy::PPB_AudioEncodeParameters& parameters,
int32_t samples_per_frame);
void DoEncode();
void BitstreamBufferReady(int32_t audio_buffer_id,
int32_t bitstream_buffer_id,
int32_t size);
void NotifyPepperError(int32_t error);
void Close();
static void StopAudioEncoder(
scoped_ptr<AudioEncoderImpl> encoder,
scoped_ptr<ppapi::MediaStreamBufferManager> audio_buffer_manager,
scoped_ptr<ppapi::MediaStreamBufferManager> bitstream_buffer_manager);
// Non-owning pointer.
RendererPpapiHost* renderer_ppapi_host_;
// Whether the encoder has been successfully initialized.
bool initialized_;
// Last error reported by the encoder.
// This represents the current error state of the encoder, i.e. PP_OK
// normally, or a Pepper error code if the encoder is uninitialized,
// has been notified of an encoder error, has encountered some
// other unrecoverable error, or has been closed by the plugin.
// This field is checked in most message handlers to decide whether
// operations should proceed or fail.
int32_t encoder_last_error_;
// Manages buffers containing audio samples from the plugin.
scoped_ptr<ppapi::MediaStreamBufferManager> audio_buffer_manager_;
// Manages buffers containing encoded audio from the browser.
scoped_ptr<ppapi::MediaStreamBufferManager> bitstream_buffer_manager_;
// Media task runner used to run the encoder.
scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
// The encoder actually doing the work.
scoped_ptr<AudioEncoderImpl> encoder_;
base::WeakPtrFactory<PepperAudioEncoderHost> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(PepperAudioEncoderHost);
};
} // namespace content
#endif // CONTENT_RENDERER_PEPPER_PEPPER_AUDIO_ENCODER_HOST_H_
......@@ -393,6 +393,8 @@
'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_compositor.cc',
......
This diff is collapsed.
......@@ -11,6 +11,7 @@
#include "base/memory/scoped_vector.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"
......@@ -20,12 +21,12 @@ class TrackedCallback;
namespace proxy {
class SerializedHandle;
class VideoFrameResource;
class AudioBufferResource;
class PPAPI_PROXY_EXPORT AudioEncoderResource
: public PluginResource,
public thunk::PPB_AudioEncoder_API {
public thunk::PPB_AudioEncoder_API,
public ppapi::MediaStreamBufferManager::Delegate {
public:
AudioEncoderResource(Connection connection, PP_Instance instance);
~AudioEncoderResource() override;
......@@ -33,7 +34,10 @@ class PPAPI_PROXY_EXPORT AudioEncoderResource
thunk::PPB_AudioEncoder_API* AsPPB_AudioEncoder_API() override;
private:
// PPB_AduioEncoder_API implementation.
// MediaStreamBufferManager::Delegate implementation.
void OnNewBufferEnqueued() override {}
// PPB_AudioEncoder_API implementation.
int32_t GetSupportedProfiles(
const PP_ArrayOutput& output,
const scoped_refptr<TrackedCallback>& callback) override;
......@@ -57,6 +61,62 @@ class PPAPI_PROXY_EXPORT AudioEncoderResource
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);
};
......
......@@ -130,6 +130,7 @@ IPC_ENUM_TRAITS(PP_VideoDecodeError_Dev)
IPC_ENUM_TRAITS(PP_VideoDecoder_Profile)
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_STRUCT_TRAITS_BEGIN(PP_Point)
......@@ -442,6 +443,14 @@ 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)
......@@ -450,6 +459,15 @@ 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()
#if !defined(OS_NACL) && !defined(NACL_WIN64)
IPC_STRUCT_TRAITS_BEGIN(ppapi::proxy::PPPDecryptor_Buffer)
......@@ -890,6 +908,32 @@ 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)
......
......@@ -13,6 +13,7 @@
#include "build/build_config.h"
#include "ppapi/c/dev/ppb_truetype_font_dev.h"
#include "ppapi/c/pp_bool.h"
#include "ppapi/c/pp_codecs.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_point.h"
#include "ppapi/c/pp_rect.h"
......@@ -121,6 +122,15 @@ struct PPPDecryptor_Buffer {
base::SharedMemoryHandle handle;
};
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;
};
// TODO(raymes): Make ImageHandle compatible with SerializedHandle.
#if defined(OS_WIN)
typedef HANDLE ImageHandle;
......
......@@ -11,7 +11,12 @@
namespace ppapi {
union MediaStreamBuffer {
enum Type { TYPE_UNKNOWN = 0, TYPE_AUDIO = 1, TYPE_VIDEO = 2, };
enum Type {
TYPE_UNKNOWN = 0,
TYPE_AUDIO = 1,
TYPE_VIDEO = 2,
TYPE_BITSTREAM = 3
};
struct Header {
Type type;
......@@ -41,16 +46,26 @@ union MediaStreamBuffer {
uint8_t data[8];
};
struct Bitstream {
Header header;
uint32_t data_size;
// Uses 8 bytes to make sure the Bitstream struct has consistent size
// between NaCl code and renderer code.
uint8_t data[8];
};
// Because these structs are written and read in shared memory, we need
// the size and alighment to be consistent between NaCl and its host trusted
// platform.
PP_COMPILE_ASSERT_SIZE_IN_BYTES(Header, 8);
PP_COMPILE_ASSERT_SIZE_IN_BYTES(Audio, 40);
PP_COMPILE_ASSERT_SIZE_IN_BYTES(Video, 40);
PP_COMPILE_ASSERT_SIZE_IN_BYTES(Bitstream, 20);
Header header;
Video video;
Audio audio;
Bitstream bitstream;
};
} // namespace ppapi
......
// 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();
}
// 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_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment