1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
|
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_NDEBUG 1
#define LOG_TAG "VideoEditorAudioPlayer"
#include <utils/Log.h>
#include <binder/IPCThreadState.h>
#include <media/AudioTrack.h>
#include <VideoEditorAudioPlayer.h>
#include <media/stagefright/MediaDebug.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/MediaSource.h>
#include <media/stagefright/MetaData.h>
#include <system/audio.h>
#include "PreviewPlayer.h"
namespace android {
VideoEditorAudioPlayer::VideoEditorAudioPlayer(
const sp<MediaPlayerBase::AudioSink> &audioSink,
PreviewPlayer *observer)
: AudioPlayerBase(audioSink, observer) {
ALOGV("VideoEditorAudioPlayer");
mBGAudioPCMFileHandle = NULL;
mAudioProcess = NULL;
mBGAudioPCMFileLength = 0;
mBGAudioPCMFileTrimmedLength = 0;
mBGAudioPCMFileDuration = 0;
mBGAudioPCMFileSeekPoint = 0;
mBGAudioPCMFileOriginalSeekPoint = 0;
mBGAudioStoryBoardSkimTimeStamp = 0;
mBGAudioStoryBoardCurrentMediaBeginCutTS = 0;
mBGAudioStoryBoardCurrentMediaVolumeVal = 0;
mSeekTimeUs = 0;
mSource = NULL;
}
VideoEditorAudioPlayer::~VideoEditorAudioPlayer() {
ALOGV("~VideoEditorAudioPlayer");
if (mStarted) {
reset();
}
if (mAudioProcess != NULL) {
delete mAudioProcess;
mAudioProcess = NULL;
}
}
void VideoEditorAudioPlayer::setSource(const sp<MediaSource> &source) {
Mutex::Autolock autoLock(mLock);
// Before setting source, stop any existing source.
// Make sure to release any buffer we hold onto so that the
// source is able to stop().
if (mFirstBuffer != NULL) {
mFirstBuffer->release();
mFirstBuffer = NULL;
}
if (mInputBuffer != NULL) {
ALOGV("VideoEditorAudioPlayer releasing input buffer.");
mInputBuffer->release();
mInputBuffer = NULL;
}
if (mSource != NULL) {
mSource->stop();
mSource.clear();
}
mSource = source;
mReachedEOS = false;
}
sp<MediaSource> VideoEditorAudioPlayer::getSource() {
Mutex::Autolock autoLock(mLock);
return mSource;
}
void VideoEditorAudioPlayer::setObserver(PreviewPlayer *observer) {
ALOGV("setObserver");
//CHECK(!mStarted);
mObserver = observer;
}
bool VideoEditorAudioPlayer::isStarted() {
return mStarted;
}
status_t VideoEditorAudioPlayer::start(bool sourceAlreadyStarted) {
Mutex::Autolock autoLock(mLock);
CHECK(!mStarted);
CHECK(mSource != NULL);
ALOGV("Start");
status_t err;
M4OSA_ERR result = M4NO_ERROR;
M4OSA_UInt32 startTime = 0;
M4OSA_UInt32 seekTimeStamp = 0;
M4OSA_Bool bStoryBoardTSBeyondBTEndCutTime = M4OSA_FALSE;
if (!sourceAlreadyStarted) {
err = mSource->start();
if (err != OK) {
return err;
}
}
// Create the BG Audio handler
mAudioProcess = new VideoEditorBGAudioProcessing();
veAudMixSettings audioMixSettings;
// Pass on the audio ducking parameters
audioMixSettings.lvInDucking_threshold =
mAudioMixSettings->uiInDucking_threshold;
audioMixSettings.lvInDucking_lowVolume =
((M4OSA_Float)mAudioMixSettings->uiInDucking_lowVolume) / 100.0;
audioMixSettings.lvInDucking_enable =
mAudioMixSettings->bInDucking_enable;
audioMixSettings.lvPTVolLevel =
((M4OSA_Float)mBGAudioStoryBoardCurrentMediaVolumeVal) / 100.0;
audioMixSettings.lvBTVolLevel =
((M4OSA_Float)mAudioMixSettings->uiAddVolume) / 100.0;
audioMixSettings.lvBTChannelCount = mAudioMixSettings->uiBTChannelCount;
audioMixSettings.lvPTChannelCount = mAudioMixSettings->uiNbChannels;
// Call to Audio mix param setting
mAudioProcess->veSetAudioProcessingParams(audioMixSettings);
// Get the BG Audio PCM file details
if ( mBGAudioPCMFileHandle ) {
// TODO : 32bits required for OSAL, to be updated once OSAL is updated
M4OSA_UInt32 tmp32 = 0;
result = M4OSA_fileReadGetOption(mBGAudioPCMFileHandle,
M4OSA_kFileReadGetFileSize,
(M4OSA_Void**)&tmp32);
mBGAudioPCMFileLength = tmp32;
mBGAudioPCMFileTrimmedLength = mBGAudioPCMFileLength;
ALOGV("VideoEditorAudioPlayer::start M4OSA_kFileReadGetFileSize = %lld",
mBGAudioPCMFileLength);
// Get the duration in time of the audio BT
if ( result == M4NO_ERROR ) {
ALOGV("VEAP: channels = %d freq = %d",
mAudioMixSettings->uiNbChannels, mAudioMixSettings->uiSamplingFrequency);
// No trim
mBGAudioPCMFileDuration = ((
(int64_t)(mBGAudioPCMFileLength/sizeof(M4OSA_UInt16)/
mAudioMixSettings->uiNbChannels))*1000 ) /
mAudioMixSettings->uiSamplingFrequency;
ALOGV("VideoEditorAudioPlayer:: beginCutMs %d , endCutMs %d",
(unsigned int) mAudioMixSettings->beginCutMs,
(unsigned int) mAudioMixSettings->endCutMs);
// Remove the trim part
if ((mAudioMixSettings->beginCutMs == 0) &&
(mAudioMixSettings->endCutMs != 0)) {
// End time itself the file duration
mBGAudioPCMFileDuration = mAudioMixSettings->endCutMs;
// Limit the file length also
mBGAudioPCMFileTrimmedLength = ((
(int64_t)(mBGAudioPCMFileDuration *
mAudioMixSettings->uiSamplingFrequency) *
mAudioMixSettings->uiNbChannels) *
sizeof(M4OSA_UInt16)) / 1000;
}
else if ((mAudioMixSettings->beginCutMs != 0) &&
(mAudioMixSettings->endCutMs == mBGAudioPCMFileDuration)) {
// End time itself the file duration
mBGAudioPCMFileDuration = mBGAudioPCMFileDuration -
mAudioMixSettings->beginCutMs;
// Limit the file length also
mBGAudioPCMFileTrimmedLength = ((
(int64_t)(mBGAudioPCMFileDuration *
mAudioMixSettings->uiSamplingFrequency) *
mAudioMixSettings->uiNbChannels) *
sizeof(M4OSA_UInt16)) / 1000;
}
else if ((mAudioMixSettings->beginCutMs != 0) &&
(mAudioMixSettings->endCutMs != 0)) {
// End time itself the file duration
mBGAudioPCMFileDuration = mAudioMixSettings->endCutMs -
mAudioMixSettings->beginCutMs;
// Limit the file length also
mBGAudioPCMFileTrimmedLength = ((
(int64_t)(mBGAudioPCMFileDuration *
mAudioMixSettings->uiSamplingFrequency) *
mAudioMixSettings->uiNbChannels) *
sizeof(M4OSA_UInt16)) / 1000; /*make to sec from ms*/
}
ALOGV("VideoEditorAudioPlayer: file duration recorded : %lld",
mBGAudioPCMFileDuration);
}
// Last played location to be seeked at for next media item
if ( result == M4NO_ERROR ) {
ALOGV("VideoEditorAudioPlayer::mBGAudioStoryBoardSkimTimeStamp %lld",
mBGAudioStoryBoardSkimTimeStamp);
ALOGV("VideoEditorAudioPlayer::uiAddCts %d",
mAudioMixSettings->uiAddCts);
if (mBGAudioStoryBoardSkimTimeStamp >= mAudioMixSettings->uiAddCts) {
startTime = (mBGAudioStoryBoardSkimTimeStamp -
mAudioMixSettings->uiAddCts);
}
else {
// do nothing
}
ALOGV("VideoEditorAudioPlayer::startTime %d", startTime);
seekTimeStamp = 0;
if (startTime) {
if (startTime >= mBGAudioPCMFileDuration) {
// The BG track should be looped and started again
if (mAudioMixSettings->bLoop) {
// Add begin cut time to the mod value
seekTimeStamp = ((startTime%mBGAudioPCMFileDuration) +
mAudioMixSettings->beginCutMs);
}else {
// Looping disabled, donot do BT Mix , set to file end
seekTimeStamp = (mBGAudioPCMFileDuration +
mAudioMixSettings->beginCutMs);
}
}else {
// BT still present , just seek to story board time
seekTimeStamp = startTime + mAudioMixSettings->beginCutMs;
}
}
else {
seekTimeStamp = mAudioMixSettings->beginCutMs;
}
// Convert the seekTimeStamp to file location
mBGAudioPCMFileOriginalSeekPoint = (
(int64_t)(mAudioMixSettings->beginCutMs)
* mAudioMixSettings->uiSamplingFrequency
* mAudioMixSettings->uiNbChannels
* sizeof(M4OSA_UInt16))/ 1000 ; /*make to sec from ms*/
mBGAudioPCMFileSeekPoint = ((int64_t)(seekTimeStamp)
* mAudioMixSettings->uiSamplingFrequency
* mAudioMixSettings->uiNbChannels
* sizeof(M4OSA_UInt16))/ 1000 ;
}
}
// We allow an optional INFO_FORMAT_CHANGED at the very beginning
// of playback, if there is one, getFormat below will retrieve the
// updated format, if there isn't, we'll stash away the valid buffer
// of data to be used on the first audio callback.
CHECK(mFirstBuffer == NULL);
mFirstBufferResult = mSource->read(&mFirstBuffer);
if (mFirstBufferResult == INFO_FORMAT_CHANGED) {
ALOGV("INFO_FORMAT_CHANGED!!!");
CHECK(mFirstBuffer == NULL);
mFirstBufferResult = OK;
mIsFirstBuffer = false;
} else {
mIsFirstBuffer = true;
}
sp<MetaData> format = mSource->getFormat();
const char *mime;
bool success = format->findCString(kKeyMIMEType, &mime);
CHECK(success);
CHECK(!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_RAW));
success = format->findInt32(kKeySampleRate, &mSampleRate);
CHECK(success);
int32_t numChannels;
success = format->findInt32(kKeyChannelCount, &numChannels);
CHECK(success);
if (mAudioSink.get() != NULL) {
status_t err = mAudioSink->open(
mSampleRate, numChannels, AUDIO_FORMAT_PCM_16_BIT,
DEFAULT_AUDIOSINK_BUFFERCOUNT,
&VideoEditorAudioPlayer::AudioSinkCallback, this);
if (err != OK) {
if (mFirstBuffer != NULL) {
mFirstBuffer->release();
mFirstBuffer = NULL;
}
if (!sourceAlreadyStarted) {
mSource->stop();
}
return err;
}
mLatencyUs = (int64_t)mAudioSink->latency() * 1000;
mFrameSize = mAudioSink->frameSize();
mAudioSink->start();
} else {
mAudioTrack = new AudioTrack(
AUDIO_STREAM_MUSIC, mSampleRate, AUDIO_FORMAT_PCM_16_BIT,
(numChannels == 2)
? AUDIO_CHANNEL_OUT_STEREO
: AUDIO_CHANNEL_OUT_MONO,
0, 0, &AudioCallback, this, 0);
if ((err = mAudioTrack->initCheck()) != OK) {
delete mAudioTrack;
mAudioTrack = NULL;
if (mFirstBuffer != NULL) {
mFirstBuffer->release();
mFirstBuffer = NULL;
}
if (!sourceAlreadyStarted) {
mSource->stop();
}
return err;
}
mLatencyUs = (int64_t)mAudioTrack->latency() * 1000;
mFrameSize = mAudioTrack->frameSize();
mAudioTrack->start();
}
mStarted = true;
return OK;
}
void VideoEditorAudioPlayer::resume() {
veAudMixSettings audioMixSettings;
// Single audio player is used;
// Pass on the audio ducking parameters
// which might have changed with new audio source
audioMixSettings.lvInDucking_threshold =
mAudioMixSettings->uiInDucking_threshold;
audioMixSettings.lvInDucking_lowVolume =
((M4OSA_Float)mAudioMixSettings->uiInDucking_lowVolume) / 100.0;
audioMixSettings.lvInDucking_enable =
mAudioMixSettings->bInDucking_enable;
audioMixSettings.lvPTVolLevel =
((M4OSA_Float)mBGAudioStoryBoardCurrentMediaVolumeVal) / 100.0;
audioMixSettings.lvBTVolLevel =
((M4OSA_Float)mAudioMixSettings->uiAddVolume) / 100.0;
audioMixSettings.lvBTChannelCount = mAudioMixSettings->uiBTChannelCount;
audioMixSettings.lvPTChannelCount = mAudioMixSettings->uiNbChannels;
// Call to Audio mix param setting
mAudioProcess->veSetAudioProcessingParams(audioMixSettings);
//Call the base class
AudioPlayerBase::resume();
}
void VideoEditorAudioPlayer::reset() {
ALOGV("reset");
AudioPlayerBase::reset();
// Capture the current seek point
mBGAudioPCMFileSeekPoint = 0;
mBGAudioStoryBoardSkimTimeStamp =0;
mBGAudioStoryBoardCurrentMediaBeginCutTS=0;
}
size_t VideoEditorAudioPlayer::AudioSinkCallback(
MediaPlayerBase::AudioSink *audioSink,
void *buffer, size_t size, void *cookie) {
VideoEditorAudioPlayer *me = (VideoEditorAudioPlayer *)cookie;
return me->fillBuffer(buffer, size);
}
size_t VideoEditorAudioPlayer::fillBuffer(void *data, size_t size) {
if (mReachedEOS) {
return 0;
}
size_t size_done = 0;
size_t size_remaining = size;
M4OSA_ERR err = M4NO_ERROR;
M4AM_Buffer16 bgFrame = {NULL, 0};
M4AM_Buffer16 mixFrame = {NULL, 0};
M4AM_Buffer16 ptFrame = {NULL, 0};
int64_t currentSteamTS = 0;
int64_t startTimeForBT = 0;
M4OSA_Float fPTVolLevel =
((M4OSA_Float)mBGAudioStoryBoardCurrentMediaVolumeVal)/100;
M4OSA_Int16 *pPTMdata=NULL;
M4OSA_UInt32 uiPCMsize = 0;
bool postSeekComplete = false;
bool postEOS = false;
while ((size_remaining > 0)&&(err==M4NO_ERROR)) {
MediaSource::ReadOptions options;
{
Mutex::Autolock autoLock(mLock);
if (mSeeking) {
if (mIsFirstBuffer) {
if (mFirstBuffer != NULL) {
mFirstBuffer->release();
mFirstBuffer = NULL;
}
mIsFirstBuffer = false;
}
options.setSeekTo(mSeekTimeUs);
if (mInputBuffer != NULL) {
mInputBuffer->release();
mInputBuffer = NULL;
}
mSeeking = false;
if (mObserver) {
postSeekComplete = true;
}
}
}
if (mInputBuffer == NULL) {
status_t status = OK;
if (mIsFirstBuffer) {
mInputBuffer = mFirstBuffer;
mFirstBuffer = NULL;
status = mFirstBufferResult;
mIsFirstBuffer = false;
} else {
{
Mutex::Autolock autoLock(mLock);
status = mSource->read(&mInputBuffer, &options);
}
// Data is Primary Track, mix with background track
// after reading same size from Background track PCM file
if (status == OK)
{
// Mix only when skim point is after startTime of BT
if (((mBGAudioStoryBoardSkimTimeStamp* 1000) +
(mPositionTimeMediaUs - mSeekTimeUs)) >=
(int64_t)(mAudioMixSettings->uiAddCts * 1000)) {
ALOGV("VideoEditorAudioPlayer::INSIDE MIXING");
ALOGV("Checking %lld <= %lld",
mBGAudioPCMFileSeekPoint-mBGAudioPCMFileOriginalSeekPoint,
mBGAudioPCMFileTrimmedLength);
M4OSA_Void* ptr;
ptr = (M4OSA_Void*)((unsigned int)mInputBuffer->data() +
mInputBuffer->range_offset());
M4OSA_UInt32 len = mInputBuffer->range_length();
M4OSA_Context fp = M4OSA_NULL;
uiPCMsize = (mInputBuffer->range_length())/2;
pPTMdata = (M4OSA_Int16*) ((uint8_t*) mInputBuffer->data()
+ mInputBuffer->range_offset());
ALOGV("mix with background malloc to do len %d", len);
bgFrame.m_dataAddress = (M4OSA_UInt16*)M4OSA_32bitAlignedMalloc( len, 1,
(M4OSA_Char*)"bgFrame");
bgFrame.m_bufferSize = len;
mixFrame.m_dataAddress = (M4OSA_UInt16*)M4OSA_32bitAlignedMalloc(len, 1,
(M4OSA_Char*)"mixFrame");
mixFrame.m_bufferSize = len;
ALOGV("mix with bgm with size %lld", mBGAudioPCMFileLength);
CHECK(mInputBuffer->meta_data()->findInt64(kKeyTime,
&mPositionTimeMediaUs));
if (mBGAudioPCMFileSeekPoint -
mBGAudioPCMFileOriginalSeekPoint <=
(mBGAudioPCMFileTrimmedLength - len)) {
ALOGV("Checking mBGAudioPCMFileHandle %d",
(unsigned int)mBGAudioPCMFileHandle);
if (mBGAudioPCMFileHandle != M4OSA_NULL) {
ALOGV("fillBuffer seeking file to %lld",
mBGAudioPCMFileSeekPoint);
// TODO : 32bits required for OSAL
M4OSA_UInt32 tmp32 =
(M4OSA_UInt32)mBGAudioPCMFileSeekPoint;
err = M4OSA_fileReadSeek(mBGAudioPCMFileHandle,
M4OSA_kFileSeekBeginning,
(M4OSA_FilePosition*)&tmp32);
mBGAudioPCMFileSeekPoint = tmp32;
if (err != M4NO_ERROR){
ALOGE("M4OSA_fileReadSeek err %d",(int)err);
}
err = M4OSA_fileReadData(mBGAudioPCMFileHandle,
(M4OSA_Int8*)bgFrame.m_dataAddress,
(M4OSA_UInt32*)&len);
if (err == M4WAR_NO_DATA_YET ) {
ALOGV("fillBuffer End of file reached");
err = M4NO_ERROR;
// We reached the end of file
// move to begin cut time equal value
if (mAudioMixSettings->bLoop) {
mBGAudioPCMFileSeekPoint =
(((int64_t)(mAudioMixSettings->beginCutMs) *
mAudioMixSettings->uiSamplingFrequency) *
mAudioMixSettings->uiNbChannels *
sizeof(M4OSA_UInt16)) / 1000;
ALOGV("fillBuffer Looping \
to mBGAudioPCMFileSeekPoint %lld",
mBGAudioPCMFileSeekPoint);
}
else {
// No mixing;
// take care of volume of primary track
if (fPTVolLevel < 1.0) {
setPrimaryTrackVolume(pPTMdata,
uiPCMsize, fPTVolLevel);
}
}
} else if (err != M4NO_ERROR ) {
ALOGV("fileReadData for audio err %d", err);
} else {
mBGAudioPCMFileSeekPoint += len;
ALOGV("fillBuffer mBGAudioPCMFileSeekPoint \
%lld", mBGAudioPCMFileSeekPoint);
// Assign the ptr data to primary track
ptFrame.m_dataAddress = (M4OSA_UInt16*)ptr;
ptFrame.m_bufferSize = len;
// Call to mix and duck
mAudioProcess->veProcessAudioMixNDuck(
&ptFrame, &bgFrame, &mixFrame);
// Overwrite the decoded buffer
memcpy((void *)ptr,
(void *)mixFrame.m_dataAddress, len);
}
}
} else if (mAudioMixSettings->bLoop){
// Move to begin cut time equal value
mBGAudioPCMFileSeekPoint =
mBGAudioPCMFileOriginalSeekPoint;
} else {
// No mixing;
// take care of volume level of primary track
if(fPTVolLevel < 1.0) {
setPrimaryTrackVolume(
pPTMdata, uiPCMsize, fPTVolLevel);
}
}
if (bgFrame.m_dataAddress) {
free(bgFrame.m_dataAddress);
}
if (mixFrame.m_dataAddress) {
free(mixFrame.m_dataAddress);
}
} else {
// No mixing;
// take care of volume level of primary track
if(fPTVolLevel < 1.0) {
setPrimaryTrackVolume(pPTMdata, uiPCMsize,
fPTVolLevel);
}
}
}
}
CHECK((status == OK && mInputBuffer != NULL)
|| (status != OK && mInputBuffer == NULL));
Mutex::Autolock autoLock(mLock);
if (status != OK) {
ALOGV("fillBuffer: mSource->read returned err %d", status);
if (mObserver && !mReachedEOS) {
postEOS = true;
}
mReachedEOS = true;
mFinalStatus = status;
break;
}
CHECK(mInputBuffer->meta_data()->findInt64(
kKeyTime, &mPositionTimeMediaUs));
mPositionTimeRealUs =
((mNumFramesPlayed + size_done / mFrameSize) * 1000000)
/ mSampleRate;
ALOGV("buffer->size() = %d, "
"mPositionTimeMediaUs=%.2f mPositionTimeRealUs=%.2f",
mInputBuffer->range_length(),
mPositionTimeMediaUs / 1E6, mPositionTimeRealUs / 1E6);
}
if (mInputBuffer->range_length() == 0) {
mInputBuffer->release();
mInputBuffer = NULL;
continue;
}
size_t copy = size_remaining;
if (copy > mInputBuffer->range_length()) {
copy = mInputBuffer->range_length();
}
memcpy((char *)data + size_done,
(const char *)mInputBuffer->data() + mInputBuffer->range_offset(),
copy);
mInputBuffer->set_range(mInputBuffer->range_offset() + copy,
mInputBuffer->range_length() - copy);
size_done += copy;
size_remaining -= copy;
}
{
Mutex::Autolock autoLock(mLock);
mNumFramesPlayed += size_done / mFrameSize;
}
if (postEOS) {
mObserver->postAudioEOS();
}
if (postSeekComplete) {
mObserver->postAudioSeekComplete();
}
return size_done;
}
void VideoEditorAudioPlayer::setAudioMixSettings(
M4xVSS_AudioMixingSettings* pAudioMixSettings) {
mAudioMixSettings = pAudioMixSettings;
}
void VideoEditorAudioPlayer::setAudioMixPCMFileHandle(
M4OSA_Context pBGAudioPCMFileHandle){
mBGAudioPCMFileHandle = pBGAudioPCMFileHandle;
}
void VideoEditorAudioPlayer::setAudioMixStoryBoardSkimTimeStamp(
M4OSA_UInt32 pBGAudioStoryBoardSkimTimeStamp,
M4OSA_UInt32 pBGAudioCurrentMediaBeginCutTS,
M4OSA_UInt32 pBGAudioCurrentMediaVolumeVal) {
mBGAudioStoryBoardSkimTimeStamp = pBGAudioStoryBoardSkimTimeStamp;
mBGAudioStoryBoardCurrentMediaBeginCutTS = pBGAudioCurrentMediaBeginCutTS;
mBGAudioStoryBoardCurrentMediaVolumeVal = pBGAudioCurrentMediaVolumeVal;
}
void VideoEditorAudioPlayer::setPrimaryTrackVolume(
M4OSA_Int16 *data, M4OSA_UInt32 size, M4OSA_Float volLevel) {
while(size-- > 0) {
*data = (M4OSA_Int16)((*data)*volLevel);
data++;
}
}
}
|