Revision f8700f52
chunker_streamer/chunker_streamer.c | ||
---|---|---|
25 | 25 |
ExternalChunk *chunk; |
26 | 26 |
AVCodecContext *pCodecCtxEnc; |
27 | 27 |
}; |
28 |
struct outstream outstream[2];
|
|
28 |
struct outstream outstream[3];
|
|
29 | 29 |
|
30 | 30 |
#define DEBUG |
31 | 31 |
#define DEBUG_AUDIO_FRAMES false |
... | ... | |
745 | 745 |
return -1; |
746 | 746 |
} |
747 | 747 |
|
748 |
outstream[2].chunk = (ExternalChunk *)malloc(sizeof(ExternalChunk)); |
|
749 |
if(!outstream[2].chunk) { |
|
750 |
fprintf(stderr, "INIT: Memory error alloc chunk!!!\n"); |
|
751 |
return -1; |
|
752 |
} |
|
753 |
outstream[2].chunk->data = NULL; |
|
754 |
outstream[2].chunk->seq = 0; |
|
755 |
dcprintf(DEBUG_CHUNKER, "INIT: chunk video %d\n", outstream[2].chunk->seq); |
|
756 |
outstream[2].pCodecCtxEnc = openVideoEncoder(video_codec, video_bitrate/3, (dest_width/4)*2, (dest_height/4)*2, pCodecCtx->time_base, codec_options); // (w/4)*2, since libx264 requires width,height to be even |
|
757 |
if (!outstream[2].pCodecCtxEnc) { |
|
758 |
return -1; |
|
759 |
} |
|
760 |
|
|
748 | 761 |
fprintf(stderr, "INIT: VIDEO timebase OUT:%d %d IN: %d %d\n", outstream[1].pCodecCtxEnc->time_base.num, outstream[1].pCodecCtxEnc->time_base.den, pCodecCtx->time_base.num, pCodecCtx->time_base.den); |
749 | 762 |
|
750 | 763 |
if(pCodec==NULL) { |
... | ... | |
862 | 875 |
fprintf(stderr, "Error initializing output module, exiting\n"); |
863 | 876 |
exit(1); |
864 | 877 |
} |
878 |
outstream[2].output = initTCPPush(peer_ip, peer_port+2); |
|
879 |
if (!outstream[2].output) { |
|
880 |
fprintf(stderr, "Error initializing output module, exiting\n"); |
|
881 |
exit(1); |
|
882 |
} |
|
865 | 883 |
#endif |
866 | 884 |
#ifdef UDPIO |
867 | 885 |
static char peer_ip[16]; |
... | ... | |
1034 | 1052 |
(unsigned char)outstream[1].pCodecCtxEnc->coded_frame->pict_type); |
1035 | 1053 |
addFrameToOutstream(&outstream[1], frame, video_outbuf); |
1036 | 1054 |
} |
1055 |
if(true) { |
|
1056 |
video_frame_size = transcodeFrame(video_outbuf, video_outbuf_size, &target_pts, pFrame, pFormatCtx->streams[videoStream]->time_base, pCodecCtx, outstream[2].pCodecCtxEnc); |
|
1057 |
if (video_frame_size <= 0) { |
|
1058 |
av_free_packet(&packet); |
|
1059 |
contFrameVideo = STREAMER_MAX(contFrameVideo-1, 0); |
|
1060 |
continue; |
|
1061 |
} |
|
1062 |
createFrame(frame, pts2ms(target_pts - ptsvideo1, pFormatCtx->streams[videoStream]->time_base), video_frame_size, |
|
1063 |
(unsigned char)outstream[2].pCodecCtxEnc->coded_frame->pict_type); |
|
1064 |
addFrameToOutstream(&outstream[2], frame, video_outbuf); |
|
1065 |
} |
|
1037 | 1066 |
|
1038 | 1067 |
|
1039 | 1068 |
//compute how long it took to encode video frame |
... | ... | |
1195 | 1224 |
//Send the chunk to an external transport/player |
1196 | 1225 |
sendChunk(outstream[0].output, chunkaudio); |
1197 | 1226 |
sendChunk(outstream[1].output, chunkaudio); |
1227 |
sendChunk(outstream[2].output, chunkaudio); |
|
1198 | 1228 |
dctprintf(DEBUG_CHUNKER, "AUDIO: just sent chunk audio %d\n", chunkaudio->seq); |
1199 | 1229 |
chunkaudio->seq = 0; //signal that we need an increase |
1200 | 1230 |
//initChunk(chunkaudio, &seq_current_chunk); |
... | ... | |
1281 | 1311 |
// Close the codec |
1282 | 1312 |
avcodec_close(pCodecCtx); |
1283 | 1313 |
avcodec_close(outstream[1].pCodecCtxEnc); |
1314 |
avcodec_close(outstream[2].pCodecCtxEnc); |
|
1284 | 1315 |
|
1285 | 1316 |
if(audioStream!=-1) { |
1286 | 1317 |
avcodec_close(aCodecCtx); |
... | ... | |
1335 | 1366 |
#ifdef TCPIO |
1336 | 1367 |
finalizeTCPChunkPusher(outstream[0].output); |
1337 | 1368 |
finalizeTCPChunkPusher(outstream[1].output); |
1369 |
finalizeTCPChunkPusher(outstream[2].output); |
|
1338 | 1370 |
#endif |
1339 | 1371 |
|
1340 | 1372 |
#ifdef USE_AVFILTER |
Also available in: Unified diff