Skip to content

Commit

Permalink
- fix warnings
Browse files Browse the repository at this point in the history
- workaround downstream sending multiple media info after transcoder reconnection
  • Loading branch information
igorshevach committed Sep 16, 2024
1 parent bab813b commit 8a11b5c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 29 deletions.
4 changes: 2 additions & 2 deletions transcoder/common/json_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ typedef struct {
#define JSON_SERIALIZE_ARRAY_END() JSON_WRITE("]"); js->shouldAddComma=true;

#define JSON_SERIALIZE_STRING(key,value) ADD_COMMA() JSON_WRITE("\"%s\": \"%s\"",key,value); js->shouldAddComma=true;
#define JSON_SERIALIZE_INT(key,value) ADD_COMMA() JSON_WRITE("\"%s\": %d",key,value); js->shouldAddComma=true;
#define JSON_SERIALIZE_INT64(key,value) ADD_COMMA() JSON_WRITE("\"%s\": %ld",key,value); js->shouldAddComma=true;
#define JSON_SERIALIZE_INT(key,value) ADD_COMMA() JSON_WRITE("\"%s\": %d",key,(int)value); js->shouldAddComma=true;
#define JSON_SERIALIZE_INT64(key,value) ADD_COMMA() JSON_WRITE("\"%s\": %ld",key,(int64_t)value); js->shouldAddComma=true;
#define JSON_SERIALIZE_BOOL(key,value) ADD_COMMA() JSON_WRITE("\"%s\": %s",key,value ? "true" : "false"); js->shouldAddComma=true;
#define JSON_SERIALIZE_DOUBLE(key,value) ADD_COMMA() JSON_WRITE("\"%s\": %.2lf",key,value); js->shouldAddComma=true;

Expand Down
92 changes: 65 additions & 27 deletions transcoder/transcode/transcode_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,37 +109,22 @@ void transcode_session_get_ack_frame_id(transcode_session_t *ctx,kmp_frame_posit
}
}

int transcode_session_set_media_info(transcode_session_t *ctx,transcode_mediaInfo_t* newMediaInfo)
{
if (ctx->currentMediaInfo) {
AVCodecParameters *currentCodecParams=ctx->currentMediaInfo->codecParams;
AVCodecParameters *newCodecParams=newMediaInfo->codecParams;
bool changed=newCodecParams->width!=currentCodecParams->width ||
newCodecParams->height!=currentCodecParams->height ||
newCodecParams->extradata_size!=currentCodecParams->extradata_size;

if (currentCodecParams->extradata_size>0 &&
newCodecParams->extradata!=NULL &&
currentCodecParams->extradata!=NULL &&
0!=memcmp(newCodecParams->extradata,currentCodecParams->extradata,currentCodecParams->extradata_size))
changed=true;

avcodec_parameters_free(&newMediaInfo->codecParams);
av_free(newMediaInfo);

if (!changed) {
LOGGER0(CATEGORY_TRANSCODING_SESSION,AV_LOG_INFO,"transcode_session_set_media_info. media info did not change");
return 0;
} else {
LOGGER0(CATEGORY_TRANSCODING_SESSION,AV_LOG_ERROR,"transcode_session_set_media_info, changing media info on the fly is currently not supported");
return -1;
}
static
int transcode_session_init_pipeline(transcode_session_t *ctx) {
if (!ctx->currentMediaInfo) {
LOGGER0(CATEGORY_TRANSCODING_SESSION,AV_LOG_ERROR,"transcode_session_init_pipeline "
"media info not set");
return -1;
}

ctx->currentMediaInfo=newMediaInfo;
if (ctx->decoders > 0) {
LOGGER0(CATEGORY_TRANSCODING_SESSION,AV_LOG_ERROR, "transcode_session_init_pipeline "
"decoder already initialized");
return -1;
}

transcode_codec_t *pDecoderContext=&ctx->decoder[0];
transcode_codec_init_decoder(pDecoderContext,newMediaInfo);
transcode_codec_init_decoder(pDecoderContext,ctx->currentMediaInfo);
sprintf(pDecoderContext->name,"Decoder for input %s",ctx->name);
ctx->decoders++;
if (init_outputs_from_config(ctx)<0) {
Expand All @@ -165,6 +150,51 @@ int transcode_session_set_media_info(transcode_session_t *ctx,transcode_mediaInf

if(ctx->outputs && !ctx->ack_handler)
ctx->ack_handler = &ctx->output[0];

return 0;
}


int transcode_session_set_media_info(transcode_session_t *ctx,transcode_mediaInfo_t* newMediaInfo)
{
if(!newMediaInfo) {
LOGGER0(CATEGORY_TRANSCODING_SESSION,AV_LOG_INFO,"transcode_session_set_media_info. newMediaInfo == NULL");
return AVERROR(EINVAL);
}

if (ctx->currentMediaInfo) {
if(ctx->decoders > 0) {
AVCodecParameters *currentCodecParams=ctx->currentMediaInfo->codecParams;
AVCodecParameters *newCodecParams=newMediaInfo->codecParams;
bool changed=newCodecParams->width!=currentCodecParams->width ||
newCodecParams->height!=currentCodecParams->height ||
newCodecParams->extradata_size!=currentCodecParams->extradata_size;

if (currentCodecParams->extradata_size>0 &&
newCodecParams->extradata!=NULL &&
currentCodecParams->extradata!=NULL &&
0!=memcmp(newCodecParams->extradata,currentCodecParams->extradata,currentCodecParams->extradata_size))
changed=true;

avcodec_parameters_free(&newMediaInfo->codecParams);
av_free(newMediaInfo);

if (!changed) {
LOGGER0(CATEGORY_TRANSCODING_SESSION,AV_LOG_INFO,"transcode_session_set_media_info. media info did not change");
return 0;
} else {
LOGGER0(CATEGORY_TRANSCODING_SESSION,AV_LOG_ERROR,"transcode_session_set_media_info, changing media info on the fly is currently not supported");
return -1;
}
} else {
avcodec_parameters_free(&ctx->currentMediaInfo->codecParams);
av_free(ctx->currentMediaInfo);
ctx->currentMediaInfo = NULL;
}
}

ctx->currentMediaInfo=newMediaInfo;

return 0;
}

Expand Down Expand Up @@ -710,6 +740,14 @@ int transcode_session_send_packet(transcode_session_t *ctx ,struct AVPacket* pac
clock_estimator_push_frame(&ctx->clock_estimator,packet->dts,packet->pos);
ctx->lastInputDts=packet->dts;
samples_stats_add(&ctx->processedStats,packet->dts,packet->pos,packet->size);

if(!ctx->decoders) {
if( (ret = transcode_session_init_pipeline(ctx)) < 0) {
LOGGER(CATEGORY_TRANSCODING_SESSION,AV_LOG_ERROR, "transcode_session_init_pipeline failed %d",ret);
return ret;
}
}

}
bool shouldDecode=false;
for (int i=0;i<ctx->outputs;i++) {
Expand Down

0 comments on commit 8a11b5c

Please sign in to comment.