Skip to content

Commit 5a2946a

Browse files
committed
KMP_PACKET_MEDIA_INFO: dump media info (including extradata in hex format)
1 parent ec4a5dd commit 5a2946a

File tree

4 files changed

+71
-2
lines changed

4 files changed

+71
-2
lines changed

transcoder/KMP/KMP.c

+64
Original file line numberDiff line numberDiff line change
@@ -781,3 +781,67 @@ bool KMP_read_ack(KMP_session_t *context,uint64_t* frame_id)
781781
}
782782
return false;
783783
}
784+
785+
static const char *hex = "0123456789ABCDEF";
786+
787+
int KMP_log_mediainfo(KMP_session_t *context,
788+
const char *category, int level,
789+
transcode_mediaInfo_t* transcodeMediaInfo) {
790+
791+
AVCodecParameters* params = transcodeMediaInfo->codecParams;
792+
793+
if(!params){
794+
return -1;
795+
}
796+
797+
char *ex = NULL;
798+
if(params->extradata_size > 0 ){
799+
ex = av_malloc(2 * params->extradata_size + 1);
800+
char *walk = ex;
801+
for(int i = 0; i < params->extradata_size; i++) {
802+
*walk++ = hex[params->extradata[i] >> 4];
803+
*walk++ = hex[params->extradata[i] & 0x0f];
804+
}
805+
*walk = '\0';
806+
}
807+
808+
if (params->codec_type == AVMEDIA_TYPE_AUDIO) {
809+
810+
LOGGER(category,level,"[%s] KMP_PACKET_MEDIA_INFO type=audio"
811+
" codec_id=%s (0x%x) samplerate=%d bps=%d channels=%d channel_layout=%d"
812+
" bitrate=%.3f kbps timescale=%d:%d"
813+
" extra_data=%s",
814+
context->sessionName,
815+
avcodec_get_name(params->codec_id),
816+
params->codec_tag,
817+
params->sample_rate,
818+
params->bits_per_coded_sample,
819+
params->channels,
820+
params->channel_layout,
821+
params->bit_rate / 1000.0, transcodeMediaInfo->timeScale.num, transcodeMediaInfo->timeScale.den,
822+
ex);
823+
}
824+
else if (params->codec_type == AVMEDIA_TYPE_VIDEO) {
825+
826+
LOGGER(category,level,"[%s] KMP_PACKET_MEDIA_INFO type=video"
827+
" codec_id=%s (0x%x) width=%d height=%d frame_rate=%d:%d"
828+
" bitrate=%.3f kbps timescale=%d:%d"
829+
" cc=%s extra_data=%s",
830+
context->sessionName,
831+
avcodec_get_name(params->codec_id),
832+
params->codec_tag,
833+
params->width,
834+
params->height,
835+
transcodeMediaInfo->frameRate.num, transcodeMediaInfo->frameRate.den,
836+
params->bit_rate / 1000.0, transcodeMediaInfo->timeScale.num, transcodeMediaInfo->timeScale.den,
837+
transcodeMediaInfo->closed_captions ? "yes" : "no",
838+
ex);
839+
}
840+
841+
if(ex) {
842+
av_free(ex);
843+
}
844+
845+
return 0;
846+
}
847+

transcoder/KMP/KMP.h

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ int KMP_send_ack( KMP_session_t *context,kmp_frame_position_t *cur_pos);
5050

5151
int KMP_close( KMP_session_t *context);
5252

53+
int KMP_log_mediainfo(KMP_session_t *context, const char *category,int level, transcode_mediaInfo_t* mediaInfo);
54+
5355

5456
int KMP_listen( KMP_session_t *context);
5557
int KMP_accept( KMP_session_t *context, KMP_session_t *client);

transcoder/receiver_server.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ int clientLoop(receiver_server_t *server,receiver_server_session_t *session,tran
107107
LOGGER(CATEGORY_RECEIVER,AV_LOG_FATAL,"[%s] Invalid mediainfo",session->stream_name);
108108
break;
109109
}
110-
LOGGER(CATEGORY_RECEIVER,AV_LOG_INFO,"[%s] received packet KMP_PACKET_MEDIA_INFO",session->stream_name);
110+
111+
KMP_log_mediainfo(transcode_session, CATEGORY_RECEIVER, AV_LOG_INFO, newParams);
111112

112113
if( (retVal = transcode_session_async_set_mediaInfo(transcode_session, newParams)) < 0)
113114
{

transcoder/transcode/transcode_session.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ int transcode_session_set_media_info(transcode_session_t *ctx,transcode_mediaInf
123123
if (currentCodecParams->extradata_size>0 &&
124124
newCodecParams->extradata!=NULL &&
125125
currentCodecParams->extradata!=NULL
126-
// FIXME: uncomment memcp!!!
126+
// FIXME: uncomment memcmp!!!
127127
&& ctx->processedStats.totalFrames > 0
128128
/*&& 0!=memcmp(newCodecParams->extradata,currentCodecParams->extradata,currentCodecParams->extradata_size)*/)
129129
changed=true;
@@ -137,6 +137,8 @@ int transcode_session_set_media_info(transcode_session_t *ctx,transcode_mediaInf
137137
} else {
138138

139139
LOGGER0(CATEGORY_TRANSCODING_SESSION,AV_LOG_ERROR,"changing media info on the fly is currently not supported");
140+
avcodec_parameters_free(&newMediaInfo->codecParams);
141+
av_free(newMediaInfo);
140142
return -1;
141143
}
142144
}

0 commit comments

Comments
 (0)