|
@@ -16,21 +16,21 @@ openFFmpegDecoderContext(AVFormatContext *fmtCtx, enum AVMediaType type, int *st
|
|
|
AVCodec *codec = avcodec_find_decoder(codecId);
|
|
|
if (codec == NULL) {
|
|
|
if (codecId == AV_CODEC_ID_PNG)
|
|
|
- LOGE("openFFmpegDecoderContext avcodec_find_decoder png not found. \n");
|
|
|
- LOGE("openFFmpegDecoderContext avcodec_find_decoder=%d not found. \n", codecId);
|
|
|
+ // LOGE("openFFmpegDecoderContext avcodec_find_decoder png not found. \n");
|
|
|
+ // LOGE("openFFmpegDecoderContext avcodec_find_decoder=%d not found. \n", codecId);
|
|
|
return -1;
|
|
|
}
|
|
|
ctx = avcodec_alloc_context3(codec);
|
|
|
|
|
|
if (!ctx || !parameters || !codec) {
|
|
|
- LOGE("openFFmpegDecoderContext init error %d ctx==null=%d parameters==null=%d codec==null=%d \n", codecId,
|
|
|
- ctx == NULL, parameters == NULL, codec == NULL);
|
|
|
+ // LOGE("openFFmpegDecoderContext init error %d ctx==null=%d parameters==null=%d codec==null=%d \n", codecId,
|
|
|
+ // ctx == NULL, parameters == NULL, codec == NULL);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
|
|
|
if ((ret = avcodec_parameters_to_context(ctx, parameters)) != 0) {
|
|
|
- Log("Failed to copy %s codec parameters to decoder context.", av_get_media_type_string(type));
|
|
|
+ // Log("Failed to copy %s codec parameters to decoder context.", av_get_media_type_string(type));
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -46,7 +46,7 @@ openFFmpegDecoderContext(AVFormatContext *fmtCtx, enum AVMediaType type, int *st
|
|
|
if ((ret = avcodec_open2(ctx, codec, NULL)) != 0) {
|
|
|
char buf[512];
|
|
|
av_strerror(ret, buf, 512);
|
|
|
- LOGE("Failed to open %s codec. error=%s \n", av_get_media_type_string(type), buf);
|
|
|
+ // LOGE("Failed to open %s codec. error=%s \n", av_get_media_type_string(type), buf);
|
|
|
return -1;
|
|
|
}
|
|
|
*decCtx = ctx;
|
|
@@ -146,16 +146,16 @@ static int av_decode(struct DecoderContext *pContext, AVPacket *pPacket, enum AV
|
|
|
|
|
|
/**
|
|
|
* 初始化解码器
|
|
|
- * @param url
|
|
|
- * @param outVideoFormat
|
|
|
- * @param force_Iframe
|
|
|
+ * @param url
|
|
|
+ * @param outVideoFormat
|
|
|
+ * @param force_Iframe
|
|
|
* @param end_time
|
|
|
- * @return
|
|
|
+ * @return
|
|
|
*/
|
|
|
long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMediaType) {
|
|
|
struct DecoderContext *dctx = (struct DecoderContext *) malloc(sizeof(struct DecoderContext));
|
|
|
if (!dctx) {
|
|
|
- LOGE("DecoderContext create fail.");
|
|
|
+ // LOGE("DecoderContext create fail.");
|
|
|
return -1;
|
|
|
}
|
|
|
memset(dctx, 0, sizeof(struct DecoderContext));
|
|
@@ -167,11 +167,14 @@ long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMedi
|
|
|
dctx->disableType = disableMediaType;
|
|
|
char err_info[512] = {0};
|
|
|
avformat_network_init();
|
|
|
+
|
|
|
+ av_log_set_level(AV_LOG_PANIC);
|
|
|
+
|
|
|
int ret = avformat_open_input(&(dctx->avformatContext), dctx->url, NULL, NULL);
|
|
|
|
|
|
if (ret != 0) {
|
|
|
av_strerror(ret, err_info, 512);
|
|
|
- Log("avformat_open_input failed %d %s. path=%s \n", ret, err_info, dctx->url);
|
|
|
+ // Log("avformat_open_input failed %d %s. path=%s \n", ret, err_info, dctx->url);
|
|
|
close_decoder((long) dctx);
|
|
|
return ret;
|
|
|
}
|
|
@@ -179,7 +182,7 @@ long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMedi
|
|
|
ret = avformat_find_stream_info(dctx->avformatContext, 0);
|
|
|
if (ret < 0) {
|
|
|
av_strerror(ret, err_info, 512);
|
|
|
- Log("Failed to retrieve input stream information msg=%s\n", err_info);
|
|
|
+ // Log("Failed to retrieve input stream information msg=%s\n", err_info);
|
|
|
close_decoder((long) dctx);
|
|
|
return ret;
|
|
|
}
|
|
@@ -197,7 +200,7 @@ long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMedi
|
|
|
|
|
|
if (dctx->st_index[AVMEDIA_TYPE_VIDEO] <0)
|
|
|
{
|
|
|
- LOGE("video stream not found.");
|
|
|
+ // LOGE("video stream not found.");
|
|
|
// return -1;
|
|
|
}
|
|
|
|
|
@@ -229,9 +232,9 @@ long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMedi
|
|
|
dctx->fps = av_q2d(as->avg_frame_rate);//拿到视频码率
|
|
|
dctx->rotate = getVideoRotate(as->metadata);
|
|
|
|
|
|
- LOGE("找到视频流 width=%d height=%d bit_rate=%d fps=%d rotate=%d\n", dctx->width,
|
|
|
- dctx->height, dctx->v_bit_rate, dctx->fps,
|
|
|
- dctx->rotate);
|
|
|
+ // LOGE("找到视频流 width=%d height=%d bit_rate=%d fps=%d rotate=%d\n", dctx->width,
|
|
|
+ // dctx->height, dctx->v_bit_rate, dctx->fps,
|
|
|
+ // dctx->rotate);
|
|
|
|
|
|
}
|
|
|
if (dctx->st_index[AVMEDIA_TYPE_AUDIO] >= 0) {
|
|
@@ -242,19 +245,19 @@ long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMedi
|
|
|
dctx->a_bit_rate = as->codecpar->bit_rate;
|
|
|
dctx->aformat = as->codecpar->format;
|
|
|
dctx->channels_layout = as->codecpar->channel_layout;
|
|
|
- LOGE("找到音频流 sampleRate=%d channels=%d bit_rate=%d aformat=%d channels_layout=%d\n",
|
|
|
- dctx->sampleRate, dctx->channels, dctx->a_bit_rate,
|
|
|
- dctx->aformat, dctx->channels_layout);
|
|
|
+ // LOGE("找到音频流 sampleRate=%d channels=%d bit_rate=%d aformat=%d channels_layout=%d\n",
|
|
|
+ // dctx->sampleRate, dctx->channels, dctx->a_bit_rate,
|
|
|
+ // dctx->aformat, dctx->channels_layout);
|
|
|
|
|
|
|
|
|
}
|
|
|
dctx->totalMs = dctx->avformatContext->duration / (AV_TIME_BASE / 1000);
|
|
|
if (dctx->start_time > dctx->totalMs) {
|
|
|
- LOGE("媒体总时长 totalMs=%lld start_time=%lld \n", dctx->totalMs, dctx->start_time);
|
|
|
+ // LOGE("媒体总时长 totalMs=%lld start_time=%lld \n", dctx->totalMs, dctx->start_time);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- LOGE("媒体总时长 totalMs=%lld \n", dctx->totalMs);
|
|
|
+ // LOGE("媒体总时长 totalMs=%lld \n", dctx->totalMs);
|
|
|
if (dctx->avformatContext->start_time != AV_NOPTS_VALUE)
|
|
|
dctx->offset = dctx->avformatContext->start_time;
|
|
|
|
|
@@ -265,7 +268,7 @@ long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMedi
|
|
|
&dctx->audioCodecContext, dctx->a_codec_id);
|
|
|
|
|
|
if (ret != 0) {
|
|
|
- LOGE("audio openFFmpegDecoderContext error!");
|
|
|
+ // LOGE("audio openFFmpegDecoderContext error!");
|
|
|
close_decoder((long) dctx);
|
|
|
return ret;
|
|
|
}
|
|
@@ -278,7 +281,7 @@ long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMedi
|
|
|
&dctx->st_index[AVMEDIA_TYPE_VIDEO],
|
|
|
&dctx->videoCodecContext, dctx->v_codec_id);
|
|
|
if (ret != 0) {
|
|
|
- LOGE("video openFFmpegDecoderContext error!");
|
|
|
+ // LOGE("video openFFmpegDecoderContext error!");
|
|
|
close_decoder((long) dctx);
|
|
|
return ret;
|
|
|
}
|
|
@@ -328,7 +331,7 @@ void seekToMs(DecoderContext *dctx, int64_t offset) {
|
|
|
}
|
|
|
|
|
|
void close_decoder(long decodec_id) {
|
|
|
- LOGE("close_decoder \n");
|
|
|
+ // LOGE("close_decoder \n");
|
|
|
if (decodec_id > 0) {
|
|
|
struct DecoderContext *ctx = (struct DecoderContext *) decodec_id;
|
|
|
if (ctx->url) {
|
|
@@ -382,7 +385,7 @@ void close_decoder(long decodec_id) {
|
|
|
ctx = NULL;
|
|
|
|
|
|
}
|
|
|
- LOGE("close_decoder out\n");
|
|
|
+ // LOGE("close_decoder out\n");
|
|
|
}
|
|
|
|
|
|
int av_read_decode_frame(long decodec_id) {
|
|
@@ -411,11 +414,11 @@ void *av_read_decode_thread(void *pVoid) {
|
|
|
AVPacket *pkg = av_packet_alloc();
|
|
|
ret = av_read_frame(ctx->avformatContext, pkg);
|
|
|
if (ret == AVERROR_EOF) {
|
|
|
- LOGE("startDecoder flush \n");
|
|
|
+ // LOGE("startDecoder flush \n");
|
|
|
av_decode(ctx, NULL, AVMEDIA_TYPE_VIDEO);
|
|
|
av_decode(ctx, NULL, AVMEDIA_TYPE_AUDIO);
|
|
|
av_packet_free(&pkg);
|
|
|
- LOGE("av_read_frame eof!\n");
|
|
|
+ // LOGE("av_read_frame eof!\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -461,12 +464,12 @@ void *av_read_decode_thread(void *pVoid) {
|
|
|
}
|
|
|
}
|
|
|
if (ctx->audio_queue){
|
|
|
- LOGE("push empty packet audio !\n");
|
|
|
+ // LOGE("push empty packet audio !\n");
|
|
|
ctx->audio_queue->PushBack(NULL);
|
|
|
}
|
|
|
- LOGE("push empty packet video !\n");
|
|
|
+ // LOGE("push empty packet video !\n");
|
|
|
ctx->video_queue->PushBack(NULL);
|
|
|
}
|
|
|
- LOGE("read thread exit !\n");
|
|
|
+ // LOGE("read thread exit !\n");
|
|
|
pthread_exit(NULL);
|
|
|
}
|