2 * various utility functions used within FFmpeg
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
5 * FFmpeg is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * FFmpeg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with FFmpeg; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 /* Functions defined here are functions that cannot be resolved through the
21 * ffmpeg shared libraries, yet are used in XBMC.
24 #if (defined HAVE_CONFIG_H) && (!defined WIN32)
27 #if (defined USE_EXTERNAL_FFMPEG)
28 #include <libavformat/avformat.h>
30 /* Taken from libavformat/utils.c */
31 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(54,0,0)
32 static void flush_packet_queue(AVFormatContext *s)
37 pktl = s->packet_buffer;
40 s->packet_buffer = pktl->next;
41 av_free_packet(&pktl->pkt);
44 while(s->raw_packet_buffer){
45 pktl = s->raw_packet_buffer;
46 s->raw_packet_buffer = pktl->next;
47 av_free_packet(&pktl->pkt);
51 s->raw_packet_buffer_end= NULL;
52 #ifdef RAW_PACKET_BUFFER_SIZE
53 // Added on: 2009-06-25
54 s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
58 static void free_packet_buffer(AVPacketList **pkt_buf, AVPacketList **pkt_buf_end)
61 AVPacketList *pktl = *pkt_buf;
62 *pkt_buf = pktl->next;
63 av_free_packet(&pktl->pkt);
68 /* XXX: suppress the packet queue */
69 static void flush_packet_queue(AVFormatContext *s)
71 free_packet_buffer(&s->parse_queue, &s->parse_queue_end);
72 free_packet_buffer(&s->packet_buffer, &s->packet_buffer_end);
73 free_packet_buffer(&s->raw_packet_buffer, &s->raw_packet_buffer_end);
75 s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
79 /* Taken from libavformat/utils.c
80 * Original name is ff_read_frame_flush
82 void xbmc_read_frame_flush(AVFormatContext *s)
87 flush_packet_queue(s);
89 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(54,0,0)
93 /* for each stream, reset read state */
94 for(i = 0; i < s->nb_streams; i++) {
98 av_parser_close(st->parser);
100 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(54,0,0)
101 av_free_packet(&st->cur_pkt);
104 st->last_IP_pts = AV_NOPTS_VALUE;
105 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(54,0,0)
106 st->cur_dts = AV_NOPTS_VALUE; /* we set the current DTS to an unspecified origin */
107 st->reference_dts = AV_NOPTS_VALUE;
112 #define RELATIVE_TS_BASE (INT64_MAX - (1LL<<48))
113 if(st->first_dts == AV_NOPTS_VALUE) st->cur_dts = RELATIVE_TS_BASE;
114 else st->cur_dts = AV_NOPTS_VALUE; /* we set the current DTS to an unspecified origin */
115 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(55,0,0)
116 st->reference_dts = AV_NOPTS_VALUE;
119 st->probe_packets = MAX_PROBE_PACKETS;
122 for(j=0; j<MAX_REORDER_DELAY+1; j++)
123 st->pts_buffer[j]= AV_NOPTS_VALUE;
126 #endif /* (defined USE_EXTERNAL_FFMPEG) */