Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1 | /*
|
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 2 | * Copyright (C) 2011 The Android Open Source Project
|
| 3 | *
|
| 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 | * you may not use this file except in compliance with the License.
|
| 6 | * You may obtain a copy of the License at
|
| 7 | *
|
| 8 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 9 | *
|
| 10 | * Unless required by applicable law or agreed to in writing, software
|
| 11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 | * See the License for the specific language governing permissions and
|
| 14 | * limitations under the License.
|
| 15 | */
|
| 16 |
|
| 17 | #define LOG_NDEBUG 1
|
| 18 | #define LOG_TAG "VideoEditorPlayer"
|
| 19 | #include <utils/Log.h>
|
| 20 |
|
| 21 | #include "VideoEditorPlayer.h"
|
| 22 | #include "PreviewPlayer.h"
|
| 23 |
|
| 24 | #include <media/Metadata.h>
|
| 25 | #include <media/stagefright/MediaExtractor.h>
|
Dima Zavin | 6859837 | 2011-04-05 16:13:49 -0700 | [diff] [blame] | 26 | |
Dima Zavin | 272eb55 | 2011-05-11 14:15:37 -0700 | [diff] [blame] | 27 | #include <system/audio.h> |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 28 |
|
| 29 | namespace android {
|
| 30 |
|
| 31 | VideoEditorPlayer::VideoEditorPlayer()
|
| 32 | : mPlayer(new PreviewPlayer) {
|
| 33 |
|
| 34 | LOGV("VideoEditorPlayer");
|
| 35 | mPlayer->setListener(this);
|
| 36 | }
|
| 37 |
|
| 38 | VideoEditorPlayer::~VideoEditorPlayer() {
|
| 39 | LOGV("~VideoEditorPlayer");
|
| 40 |
|
| 41 | reset();
|
| 42 | mVeAudioSink.clear();
|
| 43 |
|
| 44 | delete mPlayer;
|
| 45 | mPlayer = NULL;
|
| 46 | }
|
| 47 |
|
| 48 | status_t VideoEditorPlayer::initCheck() {
|
| 49 | LOGV("initCheck");
|
| 50 | return OK;
|
| 51 | }
|
| 52 |
|
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 53 |
|
| 54 | status_t VideoEditorPlayer::setAudioPlayer(VideoEditorAudioPlayer *audioPlayer) {
|
| 55 | return mPlayer->setAudioPlayer(audioPlayer);
|
| 56 | }
|
| 57 |
|
| 58 |
|
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 59 | status_t VideoEditorPlayer::setDataSource(
|
| 60 | const char *url, const KeyedVector<String8, String8> *headers) {
|
| 61 | LOGI("setDataSource('%s')", url);
|
| 62 |
|
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 63 | return mPlayer->setDataSource(url, headers);
|
| 64 | }
|
| 65 |
|
| 66 | //We donot use this in preview, dummy implimentation as this is pure virtual
|
| 67 | status_t VideoEditorPlayer::setDataSource(int fd, int64_t offset,
|
| 68 | int64_t length) {
|
| 69 | LOGE("setDataSource(%d, %lld, %lld) Not supported", fd, offset, length);
|
| 70 | return (!OK);
|
| 71 | }
|
| 72 |
|
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 73 | status_t VideoEditorPlayer::setVideoSurface(const sp<Surface> &surface) {
|
| 74 | LOGV("setVideoSurface");
|
| 75 |
|
| 76 | mPlayer->setSurface(surface);
|
| 77 | return OK;
|
| 78 | }
|
| 79 |
|
Glenn Kasten | 4aeec63 | 2011-02-14 11:56:16 -0800 | [diff] [blame] | 80 | status_t VideoEditorPlayer::setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture) {
|
| 81 | LOGV("setVideoSurfaceTexture");
|
| 82 |
|
| 83 | mPlayer->setSurfaceTexture(surfaceTexture);
|
| 84 | return OK;
|
| 85 | }
|
| 86 |
|
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 87 | status_t VideoEditorPlayer::prepare() {
|
| 88 | LOGV("prepare");
|
| 89 | return mPlayer->prepare();
|
| 90 | }
|
| 91 |
|
| 92 | status_t VideoEditorPlayer::prepareAsync() {
|
| 93 | return mPlayer->prepareAsync();
|
| 94 | }
|
| 95 |
|
| 96 | status_t VideoEditorPlayer::start() {
|
| 97 | LOGV("start");
|
| 98 | return mPlayer->play();
|
| 99 | }
|
| 100 |
|
| 101 | status_t VideoEditorPlayer::stop() {
|
| 102 | LOGV("stop");
|
| 103 | return pause();
|
| 104 | }
|
| 105 |
|
| 106 | status_t VideoEditorPlayer::pause() {
|
| 107 | LOGV("pause");
|
| 108 | return mPlayer->pause();
|
| 109 | }
|
| 110 |
|
| 111 | bool VideoEditorPlayer::isPlaying() {
|
| 112 | LOGV("isPlaying");
|
| 113 | return mPlayer->isPlaying();
|
| 114 | }
|
| 115 |
|
| 116 | status_t VideoEditorPlayer::seekTo(int msec) {
|
| 117 | LOGV("seekTo");
|
| 118 | status_t err = mPlayer->seekTo((int64_t)msec * 1000);
|
| 119 | return err;
|
| 120 | }
|
| 121 |
|
| 122 | status_t VideoEditorPlayer::getCurrentPosition(int *msec) {
|
| 123 | LOGV("getCurrentPosition");
|
| 124 | int64_t positionUs;
|
| 125 | status_t err = mPlayer->getPosition(&positionUs);
|
| 126 |
|
| 127 | if (err != OK) {
|
| 128 | return err;
|
| 129 | }
|
| 130 |
|
| 131 | *msec = (positionUs + 500) / 1000;
|
| 132 | return OK;
|
| 133 | }
|
| 134 |
|
| 135 | status_t VideoEditorPlayer::getDuration(int *msec) {
|
| 136 | LOGV("getDuration");
|
| 137 |
|
| 138 | int64_t durationUs;
|
| 139 | status_t err = mPlayer->getDuration(&durationUs);
|
| 140 |
|
| 141 | if (err != OK) {
|
| 142 | *msec = 0;
|
| 143 | return OK;
|
| 144 | }
|
| 145 |
|
| 146 | *msec = (durationUs + 500) / 1000;
|
| 147 | return OK;
|
| 148 | }
|
| 149 |
|
| 150 | status_t VideoEditorPlayer::reset() {
|
| 151 | LOGV("reset");
|
| 152 | mPlayer->reset();
|
| 153 | return OK;
|
| 154 | }
|
| 155 |
|
| 156 | status_t VideoEditorPlayer::setLooping(int loop) {
|
| 157 | LOGV("setLooping");
|
| 158 | return mPlayer->setLooping(loop);
|
| 159 | }
|
| 160 |
|
Gloria Wang | acb62af | 2011-04-25 17:29:16 -0700 | [diff] [blame] | 161 | status_t VideoEditorPlayer::setParameter(int key, const Parcel &request) { |
| 162 | LOGV("setParameter"); |
| 163 | return mPlayer->setParameter(key, request); |
| 164 | } |
| 165 | |
| 166 | status_t VideoEditorPlayer::getParameter(int key, Parcel *reply) { |
| 167 | LOGV("getParameter"); |
| 168 | return mPlayer->getParameter(key, reply); |
| 169 | } |
| 170 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 171 | player_type VideoEditorPlayer::playerType() {
|
| 172 | LOGV("playerType");
|
| 173 | return STAGEFRIGHT_PLAYER;
|
| 174 | }
|
| 175 |
|
| 176 | status_t VideoEditorPlayer::suspend() {
|
| 177 | LOGV("suspend");
|
| 178 | return mPlayer->suspend();
|
| 179 | }
|
| 180 |
|
| 181 | status_t VideoEditorPlayer::resume() {
|
| 182 | LOGV("resume");
|
| 183 | return mPlayer->resume();
|
Raghavender Palla | fa31daf | 2011-03-18 22:32:51 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | void VideoEditorPlayer::acquireLock() { |
| 187 | LOGV("acquireLock"); |
| 188 | mPlayer->acquireLock(); |
| 189 | } |
| 190 |
|
| 191 | void VideoEditorPlayer::releaseLock() {
|
| 192 | LOGV("releaseLock");
|
| 193 | mPlayer->releaseLock();
|
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 194 | }
|
| 195 |
|
| 196 | status_t VideoEditorPlayer::invoke(const Parcel &request, Parcel *reply) {
|
| 197 | return INVALID_OPERATION;
|
| 198 | }
|
| 199 |
|
| 200 | void VideoEditorPlayer::setAudioSink(const sp<AudioSink> &audioSink) {
|
| 201 | MediaPlayerInterface::setAudioSink(audioSink);
|
| 202 |
|
| 203 | mPlayer->setAudioSink(audioSink);
|
| 204 | }
|
| 205 |
|
| 206 | status_t VideoEditorPlayer::getMetadata(
|
| 207 | const media::Metadata::Filter& ids, Parcel *records) {
|
| 208 | using media::Metadata;
|
| 209 |
|
| 210 | uint32_t flags = mPlayer->flags();
|
| 211 |
|
| 212 | Metadata metadata(records);
|
| 213 |
|
| 214 | metadata.appendBool(
|
| 215 | Metadata::kPauseAvailable,
|
| 216 | flags & MediaExtractor::CAN_PAUSE);
|
| 217 |
|
| 218 | metadata.appendBool(
|
| 219 | Metadata::kSeekBackwardAvailable,
|
| 220 | flags & MediaExtractor::CAN_SEEK_BACKWARD);
|
| 221 |
|
| 222 | metadata.appendBool(
|
| 223 | Metadata::kSeekForwardAvailable,
|
| 224 | flags & MediaExtractor::CAN_SEEK_FORWARD);
|
| 225 |
|
| 226 | metadata.appendBool(
|
| 227 | Metadata::kSeekAvailable,
|
| 228 | flags & MediaExtractor::CAN_SEEK);
|
| 229 |
|
| 230 | return OK;
|
| 231 | }
|
| 232 |
|
| 233 | status_t VideoEditorPlayer::loadEffectsSettings(
|
| 234 | M4VSS3GPP_EffectSettings* pEffectSettings, int nEffects) {
|
| 235 | LOGV("loadEffectsSettings");
|
| 236 | return mPlayer->loadEffectsSettings(pEffectSettings, nEffects);
|
| 237 | }
|
| 238 |
|
| 239 | status_t VideoEditorPlayer::loadAudioMixSettings(
|
| 240 | M4xVSS_AudioMixingSettings* pAudioMixSettings) {
|
| 241 | LOGV("VideoEditorPlayer: loadAudioMixSettings");
|
| 242 | return mPlayer->loadAudioMixSettings(pAudioMixSettings);
|
| 243 | }
|
| 244 |
|
| 245 | status_t VideoEditorPlayer::setAudioMixPCMFileHandle(
|
| 246 | M4OSA_Context pAudioMixPCMFileHandle) {
|
| 247 |
|
| 248 | LOGV("VideoEditorPlayer: loadAudioMixSettings");
|
| 249 | return mPlayer->setAudioMixPCMFileHandle(pAudioMixPCMFileHandle);
|
| 250 | }
|
| 251 |
|
| 252 | status_t VideoEditorPlayer::setAudioMixStoryBoardParam(
|
| 253 | M4OSA_UInt32 audioMixStoryBoardTS,
|
| 254 | M4OSA_UInt32 currentMediaBeginCutTime,
|
| 255 | M4OSA_UInt32 primaryTrackVolValue) {
|
| 256 |
|
| 257 | LOGV("VideoEditorPlayer: loadAudioMixSettings");
|
| 258 | return mPlayer->setAudioMixStoryBoardParam(audioMixStoryBoardTS,
|
| 259 | currentMediaBeginCutTime, primaryTrackVolValue);
|
| 260 | }
|
| 261 |
|
| 262 | status_t VideoEditorPlayer::setPlaybackBeginTime(uint32_t msec) {
|
| 263 | LOGV("setPlaybackBeginTime");
|
| 264 | return mPlayer->setPlaybackBeginTime(msec);
|
| 265 | }
|
| 266 |
|
| 267 | status_t VideoEditorPlayer::setPlaybackEndTime(uint32_t msec) {
|
| 268 | LOGV("setPlaybackEndTime");
|
| 269 | return mPlayer->setPlaybackEndTime(msec);
|
| 270 | }
|
| 271 |
|
| 272 | status_t VideoEditorPlayer::setStoryboardStartTime(uint32_t msec) {
|
| 273 | LOGV("setStoryboardStartTime");
|
| 274 | return mPlayer->setStoryboardStartTime(msec);
|
| 275 | }
|
| 276 |
|
| 277 | status_t VideoEditorPlayer::setProgressCallbackInterval(uint32_t cbInterval) {
|
| 278 | LOGV("setProgressCallbackInterval");
|
| 279 | return mPlayer->setProgressCallbackInterval(cbInterval);
|
| 280 | }
|
| 281 |
|
| 282 | status_t VideoEditorPlayer::setMediaRenderingMode(
|
| 283 | M4xVSS_MediaRendering mode,
|
| 284 | M4VIDEOEDITING_VideoFrameSize outputVideoSize) {
|
| 285 |
|
| 286 | LOGV("setMediaRenderingMode");
|
| 287 | return mPlayer->setMediaRenderingMode(mode, outputVideoSize);
|
| 288 | }
|
| 289 |
|
| 290 | status_t VideoEditorPlayer::resetJniCallbackTimeStamp() {
|
| 291 | LOGV("resetJniCallbackTimeStamp");
|
| 292 | return mPlayer->resetJniCallbackTimeStamp();
|
| 293 | }
|
| 294 |
|
| 295 | status_t VideoEditorPlayer::setImageClipProperties(
|
| 296 | uint32_t width, uint32_t height) {
|
| 297 | return mPlayer->setImageClipProperties(width, height);
|
| 298 | }
|
| 299 |
|
| 300 | status_t VideoEditorPlayer::readFirstVideoFrame() {
|
| 301 | return mPlayer->readFirstVideoFrame();
|
| 302 | }
|
| 303 |
|
Santosh Madhava | b2d6e0f | 2011-02-16 22:24:42 -0800 | [diff] [blame] | 304 | status_t VideoEditorPlayer::getLastRenderedTimeMs(uint32_t *lastRenderedTimeMs) {
|
| 305 | mPlayer->getLastRenderedTimeMs(lastRenderedTimeMs);
|
| 306 | return NO_ERROR;
|
| 307 | }
|
| 308 |
|
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 309 | /* Implementation of AudioSink interface */
|
| 310 | #undef LOG_TAG
|
| 311 | #define LOG_TAG "VeAudioSink"
|
| 312 |
|
| 313 | int VideoEditorPlayer::VeAudioOutput::mMinBufferCount = 4;
|
| 314 | bool VideoEditorPlayer::VeAudioOutput::mIsOnEmulator = false;
|
| 315 |
|
| 316 | VideoEditorPlayer::VeAudioOutput::VeAudioOutput()
|
| 317 | : mCallback(NULL),
|
| 318 | mCallbackCookie(NULL) {
|
| 319 | mTrack = 0;
|
Dima Zavin | 6859837 | 2011-04-05 16:13:49 -0700 | [diff] [blame] | 320 | mStreamType = AUDIO_STREAM_MUSIC;
|
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 321 | mLeftVolume = 1.0;
|
| 322 | mRightVolume = 1.0;
|
| 323 | mLatency = 0;
|
| 324 | mMsecsPerFrame = 0;
|
| 325 | mNumFramesWritten = 0;
|
| 326 | setMinBufferCount();
|
| 327 | }
|
| 328 |
|
| 329 | VideoEditorPlayer::VeAudioOutput::~VeAudioOutput() {
|
| 330 | close();
|
| 331 | }
|
| 332 |
|
| 333 | void VideoEditorPlayer::VeAudioOutput::setMinBufferCount() {
|
| 334 |
|
| 335 | mIsOnEmulator = false;
|
Danny Fernandes | d196f1c | 2011-02-11 18:47:03 -0800 | [diff] [blame] | 336 | mMinBufferCount = 4;
|
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 337 | }
|
| 338 |
|
| 339 | bool VideoEditorPlayer::VeAudioOutput::isOnEmulator() {
|
| 340 |
|
| 341 | setMinBufferCount();
|
| 342 | return mIsOnEmulator;
|
| 343 | }
|
| 344 |
|
| 345 | int VideoEditorPlayer::VeAudioOutput::getMinBufferCount() {
|
| 346 |
|
| 347 | setMinBufferCount();
|
| 348 | return mMinBufferCount;
|
| 349 | }
|
| 350 |
|
| 351 | ssize_t VideoEditorPlayer::VeAudioOutput::bufferSize() const {
|
| 352 |
|
| 353 | if (mTrack == 0) return NO_INIT;
|
| 354 | return mTrack->frameCount() * frameSize();
|
| 355 | }
|
| 356 |
|
| 357 | ssize_t VideoEditorPlayer::VeAudioOutput::frameCount() const {
|
| 358 |
|
| 359 | if (mTrack == 0) return NO_INIT;
|
| 360 | return mTrack->frameCount();
|
| 361 | }
|
| 362 |
|
| 363 | ssize_t VideoEditorPlayer::VeAudioOutput::channelCount() const
|
| 364 | {
|
| 365 | if (mTrack == 0) return NO_INIT;
|
| 366 | return mTrack->channelCount();
|
| 367 | }
|
| 368 |
|
| 369 | ssize_t VideoEditorPlayer::VeAudioOutput::frameSize() const
|
| 370 | {
|
| 371 | if (mTrack == 0) return NO_INIT;
|
| 372 | return mTrack->frameSize();
|
| 373 | }
|
| 374 |
|
| 375 | uint32_t VideoEditorPlayer::VeAudioOutput::latency () const
|
| 376 | {
|
| 377 | return mLatency;
|
| 378 | }
|
| 379 |
|
| 380 | float VideoEditorPlayer::VeAudioOutput::msecsPerFrame() const
|
| 381 | {
|
| 382 | return mMsecsPerFrame;
|
| 383 | }
|
| 384 |
|
| 385 | status_t VideoEditorPlayer::VeAudioOutput::getPosition(uint32_t *position) {
|
| 386 |
|
| 387 | if (mTrack == 0) return NO_INIT;
|
| 388 | return mTrack->getPosition(position);
|
| 389 | }
|
| 390 |
|
| 391 | status_t VideoEditorPlayer::VeAudioOutput::open(
|
| 392 | uint32_t sampleRate, int channelCount, int format, int bufferCount,
|
| 393 | AudioCallback cb, void *cookie) {
|
| 394 |
|
| 395 | mCallback = cb;
|
| 396 | mCallbackCookie = cookie;
|
| 397 |
|
| 398 | // Check argument "bufferCount" against the mininum buffer count
|
| 399 | if (bufferCount < mMinBufferCount) {
|
Danny Fernandes | d196f1c | 2011-02-11 18:47:03 -0800 | [diff] [blame] | 400 | LOGV("bufferCount (%d) is too small and increased to %d",
|
| 401 | bufferCount, mMinBufferCount);
|
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 402 | bufferCount = mMinBufferCount;
|
| 403 |
|
| 404 | }
|
| 405 | LOGV("open(%u, %d, %d, %d)", sampleRate, channelCount, format, bufferCount);
|
| 406 | if (mTrack) close();
|
| 407 | int afSampleRate;
|
| 408 | int afFrameCount;
|
| 409 | int frameCount;
|
| 410 |
|
| 411 | if (AudioSystem::getOutputFrameCount(&afFrameCount, mStreamType) !=
|
| 412 | NO_ERROR) {
|
| 413 | return NO_INIT;
|
| 414 | }
|
| 415 | if (AudioSystem::getOutputSamplingRate(&afSampleRate, mStreamType) !=
|
| 416 | NO_ERROR) {
|
| 417 | return NO_INIT;
|
| 418 | }
|
| 419 |
|
| 420 | frameCount = (sampleRate*afFrameCount*bufferCount)/afSampleRate;
|
| 421 |
|
| 422 | AudioTrack *t;
|
| 423 | if (mCallback != NULL) {
|
| 424 | t = new AudioTrack(
|
| 425 | mStreamType,
|
| 426 | sampleRate,
|
| 427 | format,
|
| 428 | (channelCount == 2) ?
|
Dima Zavin | 6859837 | 2011-04-05 16:13:49 -0700 | [diff] [blame] | 429 | AUDIO_CHANNEL_OUT_STEREO : AUDIO_CHANNEL_OUT_MONO,
|
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 430 | frameCount,
|
| 431 | 0 /* flags */,
|
| 432 | CallbackWrapper,
|
| 433 | this);
|
| 434 | } else {
|
| 435 | t = new AudioTrack(
|
| 436 | mStreamType,
|
| 437 | sampleRate,
|
| 438 | format,
|
| 439 | (channelCount == 2) ?
|
Dima Zavin | 6859837 | 2011-04-05 16:13:49 -0700 | [diff] [blame] | 440 | AUDIO_CHANNEL_OUT_STEREO : AUDIO_CHANNEL_OUT_MONO,
|
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 441 | frameCount);
|
| 442 | }
|
| 443 |
|
| 444 | if ((t == 0) || (t->initCheck() != NO_ERROR)) {
|
| 445 | LOGE("Unable to create audio track");
|
| 446 | delete t;
|
| 447 | return NO_INIT;
|
| 448 | }
|
| 449 |
|
| 450 | LOGV("setVolume");
|
| 451 | t->setVolume(mLeftVolume, mRightVolume);
|
| 452 | mMsecsPerFrame = 1.e3 / (float) sampleRate;
|
| 453 | mLatency = t->latency();
|
| 454 | mTrack = t;
|
| 455 | return NO_ERROR;
|
| 456 | }
|
| 457 |
|
| 458 | void VideoEditorPlayer::VeAudioOutput::start() {
|
| 459 |
|
| 460 | LOGV("start");
|
| 461 | if (mTrack) {
|
| 462 | mTrack->setVolume(mLeftVolume, mRightVolume);
|
| 463 | mTrack->start();
|
| 464 | mTrack->getPosition(&mNumFramesWritten);
|
| 465 | }
|
| 466 | }
|
| 467 |
|
| 468 | void VideoEditorPlayer::VeAudioOutput::snoopWrite(
|
| 469 | const void* buffer, size_t size) {
|
| 470 | // Visualization buffers not supported
|
| 471 | return;
|
| 472 |
|
| 473 | }
|
| 474 |
|
| 475 | ssize_t VideoEditorPlayer::VeAudioOutput::write(
|
| 476 | const void* buffer, size_t size) {
|
| 477 |
|
| 478 | LOG_FATAL_IF(mCallback != NULL, "Don't call write if supplying a callback.");
|
| 479 |
|
| 480 | //LOGV("write(%p, %u)", buffer, size);
|
| 481 | if (mTrack) {
|
| 482 | snoopWrite(buffer, size);
|
| 483 | ssize_t ret = mTrack->write(buffer, size);
|
| 484 | mNumFramesWritten += ret / 4; // assume 16 bit stereo
|
| 485 | return ret;
|
| 486 | }
|
| 487 | return NO_INIT;
|
| 488 | }
|
| 489 |
|
| 490 | void VideoEditorPlayer::VeAudioOutput::stop() {
|
| 491 |
|
| 492 | LOGV("stop");
|
| 493 | if (mTrack) mTrack->stop();
|
| 494 | }
|
| 495 |
|
| 496 | void VideoEditorPlayer::VeAudioOutput::flush() {
|
| 497 |
|
| 498 | LOGV("flush");
|
| 499 | if (mTrack) mTrack->flush();
|
| 500 | }
|
| 501 |
|
| 502 | void VideoEditorPlayer::VeAudioOutput::pause() {
|
| 503 |
|
| 504 | LOGV("VeAudioOutput::pause");
|
| 505 | if (mTrack) mTrack->pause();
|
| 506 | }
|
| 507 |
|
| 508 | void VideoEditorPlayer::VeAudioOutput::close() {
|
| 509 |
|
| 510 | LOGV("close");
|
| 511 | delete mTrack;
|
| 512 | mTrack = 0;
|
| 513 | }
|
| 514 |
|
| 515 | void VideoEditorPlayer::VeAudioOutput::setVolume(float left, float right) {
|
| 516 |
|
| 517 | LOGV("setVolume(%f, %f)", left, right);
|
| 518 | mLeftVolume = left;
|
| 519 | mRightVolume = right;
|
| 520 | if (mTrack) {
|
| 521 | mTrack->setVolume(left, right);
|
| 522 | }
|
| 523 | }
|
| 524 |
|
| 525 | // static
|
| 526 | void VideoEditorPlayer::VeAudioOutput::CallbackWrapper(
|
Glenn Kasten | 72e95e7 | 2011-06-01 15:20:41 -0700 | [diff] [blame] | 527 | int event, void *cookie, void *info) {
|
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 528 | //LOGV("VeAudioOutput::callbackwrapper");
|
| 529 | if (event != AudioTrack::EVENT_MORE_DATA) {
|
| 530 | return;
|
| 531 | }
|
| 532 |
|
| 533 | VeAudioOutput *me = (VeAudioOutput *)cookie;
|
| 534 | AudioTrack::Buffer *buffer = (AudioTrack::Buffer *)info;
|
| 535 |
|
| 536 | size_t actualSize = (*me->mCallback)(
|
| 537 | me, buffer->raw, buffer->size, me->mCallbackCookie);
|
| 538 |
|
| 539 | buffer->size = actualSize;
|
| 540 |
|
| 541 | if (actualSize > 0) {
|
| 542 | me->snoopWrite(buffer->raw, actualSize);
|
| 543 | }
|
| 544 | }
|
| 545 |
|
| 546 | status_t VideoEditorPlayer::VeAudioOutput::dump(int fd, const Vector<String16>& args) const
|
| 547 | {
|
| 548 | const size_t SIZE = 256;
|
| 549 | char buffer[SIZE];
|
| 550 | String8 result;
|
| 551 |
|
| 552 | result.append(" VeAudioOutput\n");
|
| 553 | snprintf(buffer, SIZE-1, " stream type(%d), left - right volume(%f, %f)\n",
|
| 554 | mStreamType, mLeftVolume, mRightVolume);
|
| 555 | result.append(buffer);
|
| 556 | snprintf(buffer, SIZE-1, " msec per frame(%f), latency (%d)\n",
|
| 557 | mMsecsPerFrame, mLatency);
|
| 558 | result.append(buffer);
|
| 559 | ::write(fd, result.string(), result.size());
|
| 560 | if (mTrack != 0) {
|
| 561 | mTrack->dump(fd, args);
|
| 562 | }
|
| 563 | return NO_ERROR;
|
| 564 | }
|
| 565 |
|
| 566 | int VideoEditorPlayer::VeAudioOutput::getSessionId() {
|
| 567 |
|
| 568 | return mSessionId;
|
| 569 | }
|
| 570 |
|
| 571 | } // namespace android
|