Commit 529337d9 authored by Chris Cunningham's avatar Chris Cunningham Committed by Commit Bot

WebCodecs: Copy decoded output to AudioBuffer

AudioFrame will now contain real audio output!

Bug: 1094084
Change-Id: I4f0c2388f843afbfedc8713352492cb469061ea5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2339671
Commit-Queue: Chrome Cunningham <chcunningham@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Auto-Submit: Chrome Cunningham <chcunningham@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798450}
parent 55c35d13
...@@ -3,7 +3,10 @@ ...@@ -3,7 +3,10 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "third_party/blink/renderer/modules/webcodecs/audio_frame.h" #include "third_party/blink/renderer/modules/webcodecs/audio_frame.h"
#include "media/base/audio_buffer.h"
#include "media/base/audio_bus.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_audio_frame_init.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_audio_frame_init.h"
#include "third_party/blink/renderer/modules/webaudio/audio_buffer.h"
namespace blink { namespace blink {
...@@ -19,7 +22,26 @@ AudioFrame::AudioFrame(AudioFrameInit* init) ...@@ -19,7 +22,26 @@ AudioFrame::AudioFrame(AudioFrameInit* init)
AudioFrame::AudioFrame(scoped_refptr<media::AudioBuffer> buffer) AudioFrame::AudioFrame(scoped_refptr<media::AudioBuffer> buffer)
: timestamp_(buffer->timestamp().InMicroseconds()) { : timestamp_(buffer->timestamp().InMicroseconds()) {
// FIXME - use the |buffer| to initialize AudioBuffer. buffer_ = AudioBuffer::CreateUninitialized(
buffer->channel_count(), buffer->frame_count(), buffer->sample_rate());
// Wrap blink buffer a media::AudioBus so we can interface with
// media::AudioBuffer to copy the data out.
auto media_bus_wrapper =
media::AudioBus::CreateWrapper(buffer->channel_count());
for (int i = 0; i < media_bus_wrapper->channels(); ++i) {
DCHECK_EQ(buffer_->getChannelData(i)->byteLengthAsSizeT(),
buffer->frame_count() * sizeof(float));
float* channel_data = buffer_->getChannelData(i)->Data();
media_bus_wrapper->SetChannelData(i, channel_data);
}
media_bus_wrapper->set_frames(buffer->frame_count());
// Copy the frames.
// TODO(chcunningham): Avoid this copy by refactoring blink::AudioBuffer to
// ref a media::AudioBuffer and only copy for calls to copyToChannel().
buffer->ReadFrames(media_bus_wrapper->frames(), 0 /* source_frame_offset */,
0 /* dest_frame_offset */, media_bus_wrapper.get());
} }
void AudioFrame::close() { void AudioFrame::close() {
......
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