Skip to content

Commit 001a37b

Browse files
committed
增加‘dump信息打印控制‘宏定义 在build.gradle中打开
1 parent 554cd3c commit 001a37b

File tree

13 files changed

+91
-31
lines changed

13 files changed

+91
-31
lines changed

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ android {
99

1010
externalNativeBuild {
1111
ndkBuild {
12-
cFlags "-D__STDC_CONSTANT_MACROS","-std=c11","-O3","-Werror","-Wall"
12+
cFlags "-D__STDC_CONSTANT_MACROS","-std=c11","-O3","-Werror","-Wall"//,
13+
//"-DTRACE_LOCAL_FILE_DEMUXER=1",
14+
// "-DTRACE_VIDEO_DECODE=1", "-DTRACE_AUDIO_TRACK=1",
15+
// "-DTRACE_PACKET_MANAGER=1","-DTRACE_BUFFER_MANAGER=1",
1316
cppFlags "-std=c++11","-Wall","-fno-exceptions","-fno-rtti","-O3","-Werror","-Wall"
1417
}
1518
}
@@ -66,7 +69,6 @@ android {
6669
libarmeabi7aFlavors {
6770
externalNativeBuild {
6871
ndkBuild {
69-
7072
targets 'demo_ffmpeg'
7173
}
7274
ndk {

app/src/main/java/com/catdroid/demo/FFmpegActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ public void onClick(View v) {
103103
mPlayer = new DragonPlayer();
104104
mPlayer.setSurface(mSh.getSurface());
105105
//mPlayer.setDataSource("file:///mnt/sdcard/screen_mic_main_r30_g30_ultrafast_c2_44k_6000K_128K_yuv444.mp4");
106-
//mPlayer.setDataSource("file:///mnt/sdcard/1080p60fps.mp4");
107-
mPlayer.setDataSource("file:///mnt/sdcard/test.3gp");
106+
mPlayer.setDataSource("file:///mnt/sdcard/1080p60fps.mp4");
107+
//mPlayer.setDataSource("file:///mnt/sdcard/test.3gp");
108108
mPlayer.setOnPreparedListener(new DragonPlayer.OnPreparedListener(){
109109
@Override
110110
public void onPrepared(DragonPlayer mp, int what) {

app/src/main/jni/Android.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
###################################################################################
33
LOCAL_PATH := $(call my-dir)
4-
FFMPEG_LIB_ROOT_PATH := /home/hanlon/Cat6/git_qq_yun/ffmpeg/android/
5-
4+
#FFMPEG_LIB_ROOT_PATH := /home/hanlon/Cat6/git_qq_yun/ffmpeg/android/
5+
FFMPEG_LIB_ROOT_PATH := X:\\OpenSource\\ffmpeg\\android
66
include $(CLEAR_VARS)
77
LOCAL_MODULE := avcodec
88
LOCAL_SRC_FILES := $(FFMPEG_LIB_ROOT_PATH)/$(TARGET_ARCH_ABI)/lib/libavcodec.so

app/src/main/jni/Application.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
#arm64-v8a armeabi-v7a armeabi
3-
APP_ABI := arm64-v8a
3+
APP_ABI := arm64-v8a armeabi-v7a
44
APP_STL := gnustl_shared
55
APP_PLATFORM := android-21
66

app/src/main/jni/codec/decode/soft/AACSWDecoder.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,16 @@ void AACSWDecoder::deqloop(){
354354
int32_t len = swr_convert(mpSwrCtx, lineaddr, mDecodedFrameSize,
355355
(const uint8_t **) pFrame->data, pFrame->nb_samples);
356356
if (len > 0) {
357-
//每声道采样数 x 声道数 x 每个采样字节数
358-
int resampled_data_size =
357+
#if TRACE_DECODE == 1
358+
//每声道采样数 x 声道数 x 每个采样字节数
359+
int resampled_data_size =
359360
len * mpAudCtx->channels * av_get_bytes_per_sample(AV_SAMPLE_FMT_S16);
360361
TLOGD("len = %d resampled_data_size = %d mDecodedFrameSize = %d ",
361362
len, // 每个通道/平面的样本数
362363
resampled_data_size,
363364
mDecodedFrameSize
364365
);
366+
#endif
365367
buf->size() = mDecodedFrameSize;
366368
buf->pts() = (int64_t) (pFrame->pts * 1000 * 1000 * mTimeBase ); // us
367369

@@ -388,9 +390,13 @@ void AACSWDecoder::deqloop(){
388390
}break;
389391
case AVERROR(EAGAIN):{
390392
// TODO 目前只是休眠
393+
#if TRACE_DECODE == 1
391394
TLOGW("deqloop no output enter \n");
395+
#endif
392396
usleep(8000);
397+
#if TRACE_DECODE == 1
393398
TLOGW("deqloop no output exit \n");
399+
#endif
394400
}break;
395401
case AVERROR(EINVAL):{
396402
TLOGE("deqloop 参数错误\n");
@@ -508,7 +514,9 @@ bool AACSWDecoder::put(sp<MyPacket> packet , bool wait ){
508514
}
509515
mPktQueue.push_back(packet);
510516
mEnqSikCnd->signal();
517+
#if TRACE_DECODE == 1
511518
TLOGT("pending AVPacket %lu" , mPktQueue.size() );
519+
#endif
512520
return true ;
513521
}
514522
return false ;// 已经stop()

app/src/main/jni/codec/decode/soft/H264SWDecoder.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extern "C"{
2222

2323
CLASS_LOG_IMPLEMENT(H264SWDecoder,"H264SWDecoder");
2424

25-
//#define TRACE_DECODE 1
25+
//#define TRACE_VIDEO_DECODE 1
2626

2727
#define MAX_PACKET_QUEUE_SIZE 20
2828
H264SWDecoder::H264SWDecoder():
@@ -100,6 +100,7 @@ bool H264SWDecoder::init(const AVCodecParameters* para , double timebase )
100100
snprintf(newName, 16, "H264_%p", this); // H264_0x7f9abf30
101101
prctl(PR_SET_NAME, newName);
102102

103+
TLOGI("cpu count %d " , av_cpu_count() );
103104

104105
av_dict_set(&opt, "threads", "auto", 0); // add an entry: 线程数 小米5(晓龙820)是4个线程
105106
if((ret = avcodec_open2(mpVidCtx, vcodec, &opt )) < 0){
@@ -108,6 +109,11 @@ bool H264SWDecoder::init(const AVCodecParameters* para , double timebase )
108109
}else{
109110
TLOGD("编码上下文 %p, 编码器ID %d", mpVidCtx, mpVidCtx->codec_id );
110111
}
112+
113+
/*
114+
* av_image_get_buffer_size Image 视频
115+
* av_samples_get_buffer_size Sample 音频
116+
*/
111117
mDecodedFrameSize = av_image_get_buffer_size(mpVidCtx->pix_fmt , mpVidCtx->width, mpVidCtx->height , 1 );
112118

113119
mBufMgr = new BufferManager("yuv" , (uint32_t)mDecodedFrameSize, 30 );
@@ -284,12 +290,14 @@ bool H264SWDecoder::put(sp<MyPacket> packet , bool wait ){
284290
while(!mStop){// 当stop()之后调用put只会立刻释放MyPacket
285291
AutoMutex l(mEnqMux);
286292
if( mPktQueue.size() == MAX_PACKET_QUEUE_SIZE ){
293+
#if TRACE_VIDEO_DECODE == 1
287294
TLOGW("too much video AVPacket wait!");
295+
#endif
288296
// 当前已经有很多没有解码的AVPacket
289297
// 1.这里阻塞Muxer 等待解码完成
290298
// 2.可以不阻塞 立刻返回 采用丢帧方法(需要同步关键帧)
291299
if(wait){
292-
#if TRACE_DECODE == 1
300+
#if TRACE_VIDEO_DECODE == 1
293301
TLOGT("deMuxer wait for H264SWDecoder enter");
294302
#endif
295303
mFlush = false ;
@@ -299,7 +307,7 @@ bool H264SWDecoder::put(sp<MyPacket> packet , bool wait ){
299307
return true ;// drop old
300308
}
301309

302-
#if TRACE_DECODE == 1
310+
#if TRACE_VIDEO_DECODE == 1
303311
TLOGT("deMuxer wait for H264SWDecoder exit");
304312
#endif
305313
continue ;
@@ -309,7 +317,9 @@ bool H264SWDecoder::put(sp<MyPacket> packet , bool wait ){
309317
}
310318
mPktQueue.push_back(packet);
311319
mEnqSikCnd->signal();
320+
#if TRACE_VIDEO_DECODE == 1
312321
TLOGT("pending AVPacket %lu" , mPktQueue.size() );
322+
#endif
313323
return true ;
314324
}
315325
return false ;// 已经stop()
@@ -426,7 +436,7 @@ void H264SWDecoder::enqloop(){
426436
*
427437
* ps -t -p 可以看到5个 H264_xxx 线程 都在运行状态
428438
*/
429-
#if TRACE_DECODE == 1
439+
#if TRACE_VIDEO_DECODE == 1
430440
TLOGT("try to send video packet ");
431441
#endif
432442
ret = avcodec_send_packet(mpVidCtx,avpkt);
@@ -439,7 +449,7 @@ void H264SWDecoder::enqloop(){
439449
TLOGW("End Of file, send Empty Packet to Decoder done");
440450
break;
441451
}
442-
#if TRACE_DECODE == 1
452+
#if TRACE_VIDEO_DECODE == 1
443453
TLOGT(">[dts %ld pts %ld size %d] %02x %02x %02x %02x %02x" ,
444454
avpkt->dts, avpkt->pts, avpkt->size,// 对于H264来说 包含 用4个字节大端表示的NALU大小 + NALU
445455
avpkt->data?avpkt->data[0]:0xFF, // 从AVFormatContext获取 或者 放到AVCodecContext的H264不包含前引导码00000001/000001
@@ -463,7 +473,7 @@ void H264SWDecoder::enqloop(){
463473
// TODO 两个条件变量
464474
// TODO 通知 avcodec_receive_frame 从EAGAIN等待条件变量中 返回
465475
// TODO 等待 avcodec_receive_frame 返回EAGAIN 从而唤醒自己
466-
#if TRACE_DECODE == 1
476+
#if TRACE_VIDEO_DECODE == 1
467477
TLOGW("enqloop input full enter \n");
468478
#endif
469479
usleep(5000);
@@ -474,7 +484,7 @@ void H264SWDecoder::enqloop(){
474484
// mDeqCond.signal();
475485
// mEnqCond.wait(mEnqDeqMux);
476486
// }
477-
#if TRACE_DECODE == 1
487+
#if TRACE_VIDEO_DECODE == 1
478488
TLOGW("enqloop input full exit \n");
479489
#endif
480490
if(!mStop) goto TRY_AGAIN ;
@@ -553,7 +563,7 @@ void H264SWDecoder::deqloop(){
553563
while ( !mStop & !end ) {
554564
{
555565
AutoMutex _l(mSndRcvMux);
556-
#if TRACE_DECODE == 1
566+
#if TRACE_VIDEO_DECODE == 1
557567
TLOGT("try to receive video frame");
558568
#endif
559569
ret = avcodec_receive_frame(mpVidCtx, pFrame); // non-block
@@ -564,7 +574,7 @@ void H264SWDecoder::deqloop(){
564574
// pFrame->pts = av_frame_get_best_effort_timestamp(pFrame);
565575
// }
566576

567-
#if TRACE_DECODE == 1
577+
#if TRACE_VIDEO_DECODE == 1
568578
AVColorSpace cs = av_frame_get_colorspace(pFrame) ; // 目前看都是 AVCOL_SPC_UNSPECIFIED 2
569579
AVPixelFormat pixfmt = mpVidCtx->pix_fmt ; // 这个参数重要
570580
TLOGT("<[pts %" PRId64 " pkt_dts %" PRId64 " pkt_pts %" PRId64 "]"
@@ -655,7 +665,7 @@ void H264SWDecoder::deqloop(){
655665
// the only guarantee is that an AVERROR(EAGAIN) return value on a send/receive call on one end
656666
// implies that a receive/send call on the other end will succeed
657667
// 即是: 只保证一端返回AVERROR(EAGAIN)意味另外一端可以返回成功
658-
#if TRACE_DECODE == 1
668+
#if TRACE_VIDEO_DECODE == 1
659669
TLOGW("deqloop no output enter \n");
660670
#endif
661671
usleep(5000);
@@ -665,7 +675,7 @@ void H264SWDecoder::deqloop(){
665675
// mEnqCond.signal();
666676
// mDeqCond.wait(mEnqDeqMux);
667677
// }
668-
#if TRACE_DECODE == 1
678+
#if TRACE_VIDEO_DECODE == 1
669679
TLOGW("deqloop no output exit \n");
670680
#endif
671681
}break;

app/src/main/jni/common/BufferManager.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
CLASS_LOG_IMPLEMENT(BufferManager,"BufferManager");
1111

12-
#define TRACE_BUFFERMANAGER 0
12+
//#define TRACE_BUFFER_MANAGER 1
1313

1414
BufferManager::BufferManager(const char* const who, uint32_t perBufSize , uint32_t maxBufs)
1515
:mNativeSize(0),mPerBufSize(perBufSize),mMaxFreeBufs(maxBufs) {
@@ -38,7 +38,7 @@ sp<Buffer> BufferManager::pop()
3838
}
3939
mNativeSize += mPerBufSize;
4040
mTotalBuffers.push_back(pbuf);
41-
#if TRACE_BUFFERMANAGER == 1
41+
#if TRACE_BUFFER_MANAGER == 1
4242
TLOGT("%s malloc one buffer %p , mNativeSize %" PRId64 " free %lu total %lu",
4343
mWho, pbuf, mNativeSize , mFreeBuffers.size(),mTotalBuffers.size() );
4444
#endif
@@ -47,7 +47,7 @@ sp<Buffer> BufferManager::pop()
4747
Buffer* pbuf =mFreeBuffers.front();
4848
mFreeBuffers.pop_front();
4949
pbuf->reset(this);
50-
#if TRACE_BUFFERMANAGER == 1
50+
#if TRACE_BUFFER_MANAGER == 1
5151
TLOGT("%s get from free list %p free %lu total %lu " ,
5252
mWho, pbuf, mFreeBuffers.size() ,mTotalBuffers.size() );
5353
#endif
@@ -64,20 +64,20 @@ void BufferManager::push(Buffer *pbuf)
6464
// Buffer最大数目由外部控制,所以mTotalBuffer.size()可能会一直增大,如果外部获取Buffer的速率一直大于释放Buffer的速率
6565
mTotalBuffers.remove(pbuf);
6666
mNativeSize-= mPerBufSize ;
67-
#if TRACE_BUFFERMANAGER == 1
67+
#if TRACE_BUFFER_MANAGER == 1
6868
TLOGT("%s free one buffer %p [FULL] mNativeSize %" PRId64 " free %lu total %lu" ,
6969
mWho, pbuf , mNativeSize,mFreeBuffers.size(),mTotalBuffers.size() );
7070
#endif
7171
delete pbuf;
7272
}else{
7373
mFreeBuffers.push_back(pbuf);
7474
pbuf->mBM = NULL;
75-
#if TRACE_BUFFERMANAGER == 1
75+
#if TRACE_BUFFER_MANAGER == 1
7676
TLOGT("%s put to free list %p free %lu total %lu" ,
7777
mWho, pbuf , mFreeBuffers.size() ,mTotalBuffers.size() );
7878
#endif
7979
}
80-
#if TRACE_BUFFERMANAGER == 1
80+
#if TRACE_BUFFER_MANAGER == 1
8181
TLOGT("%s after push ref_count %d " , mWho, this->ref_count() );
8282
#endif
8383
}
@@ -89,7 +89,7 @@ BufferManager::~BufferManager()
8989
it != mTotalBuffers.end(); it++) {
9090
Buffer *pbuf = *it;
9191
delete pbuf;
92-
#if TRACE_BUFFERMANAGER == 1
92+
#if TRACE_BUFFER_MANAGER == 1
9393
TLOGT("%s free one buffer %p" , mWho , pbuf);
9494
#endif
9595
}

app/src/main/jni/common/MyPacket.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ sp<MyPacket> PacketManager::pop()
2323
// catch (bad_alloc new_error){
2424
//
2525
//}
26+
#if TRACE_PACKET_MANAGER == 1
2627
ALOGD("%p new one packet %p" , this , pbuf );
28+
#endif
2729
mTotalPackets.push_back(pbuf);
2830
return pbuf ;
2931
}else{
@@ -41,10 +43,14 @@ void PacketManager::push(MyPacket *pbuf)
4143
// mFreePackets.size() ,mTotalPackets.size(), mMaxPackets , this->ref_count() );
4244
if(mFreePackets.size() >= mMaxPackets ){
4345
mTotalPackets.remove(pbuf);
46+
#if TRACE_PACKET_MANAGER == 1
4447
ALOGD("%p free one packet %p [FULL]" , this , pbuf );
48+
#endif
4549
delete pbuf; // 导致析构 MyPacket.mPm 在这里 = NULL 所以不能返回后调用 mPm = NULL ;
4650
}else{
51+
#if TRACE_PACKET_MANAGER == 1
4752
ALOGD("%p put to freePackets %p [before size %lu] " ,this , pbuf , mFreePackets.size() );
53+
#endif
4854
mFreePackets.push_back(pbuf);
4955
pbuf->mPm = NULL ; // 已经把MyPacket还给 PacketManager 取消对PacketManager的引用
5056
}
@@ -57,7 +63,9 @@ PacketManager::~PacketManager()
5763
it != mTotalPackets.end(); it++)
5864
{
5965
MyPacket *pbuf = *it;
66+
#if TRACE_PACKET_MANAGER == 1
6067
ALOGD("%p deconstructor free one packet %p" , this ,pbuf );
68+
#endif
6169
delete pbuf;
6270
}
6371
ALOGD("%p deconstructor done" , this );

app/src/main/jni/demux/local/LocalFileDemuxer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,13 @@ void LocalFileDemuxer::loop()
510510

511511
// while [ 1 ] ; do adb shell ps -t 32058 ; sleep 1 ; done;
512512
if (pkt->packet()->stream_index == mAstream && mADecoder != NULL ) {
513+
#if TRACE_LOCAL_FILE_DEMUXER == 1
513514
TLOGD("audio dts = %ld , pts=%f,dts=%f,duration %f" ,
514515
pkt->packet()->dts ,
515516
pkt->packet()->pts * mATimebase ,
516517
pkt->packet()->dts * mATimebase ,
517518
pkt->packet()->duration* mATimebase );
519+
#endif
518520
//pkt->pts = pkt->pts * audio_timebase * 1000 ; // 强制改变时间戳 ms
519521
mADecoder->put(pkt , true );
520522

@@ -524,11 +526,13 @@ void LocalFileDemuxer::loop()
524526
* video dts = -1502 , pts=0.000000,dts=-0.016689,duration 0.016678
525527
* video dts = 0 , pts=0.016689,dts=0.000000,duration 0.016678
526528
* */
529+
#if TRACE_LOCAL_FILE_DEMUXER == 1
527530
TLOGD("video dts = %ld , pts=%f,dts=%f,duration %f" ,
528531
pkt->packet()->dts ,
529532
pkt->packet()->pts * mVTimebase ,
530533
pkt->packet()->dts * mVTimebase ,
531534
pkt->packet()->duration* mVTimebase );
535+
#endif
532536
//pkt->dts = pkt->dts * video_timebase * 1000 ;
533537
//pkt->pts = pkt->pts * video_timebase * 1000 ; // 强制改变时间戳 ms
534538
mVDecoder->put(pkt,true);

0 commit comments

Comments
 (0)