Merge remote-tracking branch 'tuxbox/master'

This commit is contained in:
Stefan Seyfried
2017-03-07 19:43:06 +01:00
54 changed files with 216 additions and 51 deletions

View File

@@ -60,6 +60,10 @@
#include <gui/movieplayer.h>
#include <cs_api.h>
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57, 8, 0 ))
#define av_packet_unref av_free_packet
#endif
/* experimental mode:
* stream not possible, if record running
* pids in url ignored, and added from channel, with fake PAT/PMT
@@ -756,8 +760,13 @@ void CStreamStream::Close()
if (avio_ctx)
av_free(avio_ctx);
if (bsfc)
if (bsfc){
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,52,100 ))
av_bitstream_filter_close(bsfc);
#else
av_bsf_free(&bsfc);
#endif
}
ifcx = NULL;
ofcx = NULL;
@@ -840,21 +849,35 @@ bool CStreamStream::Open()
av_dict_copy(&ofcx->metadata, ifcx->metadata, 0);
int stid = 0x200;
for (unsigned i = 0; i < ifcx->nb_streams; i++) {
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,5,0 ))
AVCodecContext * iccx = ifcx->streams[i]->codec;
AVStream *ost = avformat_new_stream(ofcx, iccx->codec);
avcodec_copy_context(ost->codec, iccx);
#else
AVCodecParameters * iccx = ifcx->streams[i]->codecpar;
AVStream *ost = avformat_new_stream(ofcx, NULL);
avcodec_parameters_copy(ost->codecpar, iccx);
#endif
av_dict_copy(&ost->metadata, ifcx->streams[i]->metadata, 0);
ost->time_base = iccx->time_base;
ost->time_base = ifcx->streams[i]->time_base;
ost->id = stid++;
}
av_log_set_level(AV_LOG_VERBOSE);
av_dump_format(ofcx, 0, ofcx->filename, 1);
av_log_set_level(AV_LOG_WARNING);
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,52,100 ))
bsfc = av_bitstream_filter_init("h264_mp4toannexb");
if (!bsfc)
printf("%s: av_bitstream_filter_init h264_mp4toannexb failed!\n", __FUNCTION__);
#else
const AVBitStreamFilter *bsf = av_bsf_get_by_name("h264_mp4toannexb");
if(!bsf) {
return false;
}
if ((av_bsf_alloc(bsf, &bsfc))) {
return false;
}
#endif
return true;
}
@@ -899,15 +922,34 @@ void CStreamStream::run()
if (pkt.stream_index < 0)
continue;
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,5,0 ))
AVCodecContext *codec = ifcx->streams[pkt.stream_index]->codec;
#else
AVCodecParameters *codec = ifcx->streams[pkt.stream_index]->codecpar;
#endif
if (bsfc && codec->codec_id == AV_CODEC_ID_H264 ) {
AVPacket newpkt = pkt;
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,52,100 ))
if (av_bitstream_filter_filter(bsfc, codec, NULL, &newpkt.data, &newpkt.size, pkt.data, pkt.size, pkt.flags & AV_PKT_FLAG_KEY) >= 0) {
av_packet_unref(&pkt);
newpkt.buf = av_buffer_create(newpkt.data, newpkt.size, av_buffer_default_free, NULL, 0);
pkt = newpkt;
}
}
#else
int ret = av_bsf_send_packet(bsfc, &pkt);
if (ret < 0){
break;
}
ret = av_bsf_receive_packet(bsfc, &newpkt);
if (ret == AVERROR(EAGAIN)){
break;
}
if(ret != AVERROR_EOF){
av_packet_unref(&pkt);
newpkt.buf = av_buffer_create(newpkt.data, newpkt.size, av_buffer_default_free, NULL, 0);
pkt = newpkt;
}
#endif
}
pkt.pts = av_rescale_q(pkt.pts, ifcx->streams[pkt.stream_index]->time_base, ofcx->streams[pkt.stream_index]->time_base);
pkt.dts = av_rescale_q(pkt.dts, ifcx->streams[pkt.stream_index]->time_base, ofcx->streams[pkt.stream_index]->time_base);