Merge pull request #4314 from MartijnKaijser/beta1
[vuplus_xbmc] / lib / xbmc-dll-symbols / DllAvFormat.c
1 /*
2  * various utility functions used within FFmpeg
3  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4  *
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.
9  *
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.
14  *
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
18  */
19
20 /* Functions defined here are functions that cannot be resolved through the
21  * ffmpeg shared libraries, yet are used in XBMC.
22  */
23
24 #if (defined HAVE_CONFIG_H) && (!defined WIN32)
25   #include "config.h"
26 #endif
27 #if (defined USE_EXTERNAL_FFMPEG)
28 #include <libavformat/avformat.h>
29
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)
33 {
34     AVPacketList *pktl;
35
36     for(;;) {
37         pktl = s->packet_buffer;
38         if (!pktl)
39             break;
40         s->packet_buffer = pktl->next;
41         av_free_packet(&pktl->pkt);
42         av_free(pktl);
43     }
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);
48         av_free(pktl);
49     }
50     s->packet_buffer_end=
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;
55 #endif
56 }
57 #else
58 static void free_packet_buffer(AVPacketList **pkt_buf, AVPacketList **pkt_buf_end)
59 {
60     while (*pkt_buf) {
61         AVPacketList *pktl = *pkt_buf;
62         *pkt_buf = pktl->next;
63         av_free_packet(&pktl->pkt);
64         av_freep(&pktl);
65     }
66     *pkt_buf_end = NULL;
67 }
68 /* XXX: suppress the packet queue */
69 static void flush_packet_queue(AVFormatContext *s)
70 {
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);
74
75     s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
76 }
77 #endif
78
79 /* Taken from libavformat/utils.c
80  * Original name is ff_read_frame_flush
81  * */
82 void xbmc_read_frame_flush(AVFormatContext *s)
83 {
84     AVStream *st;
85     int i, j;
86
87     flush_packet_queue(s);
88
89 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(54,0,0)
90     s->cur_st = NULL;
91 #endif
92
93     /* for each stream, reset read state */
94     for(i = 0; i < s->nb_streams; i++) {
95         st = s->streams[i];
96
97         if (st->parser) {
98             av_parser_close(st->parser);
99             st->parser = NULL;
100 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(54,0,0)
101             av_free_packet(&st->cur_pkt);
102 #endif
103         }
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;
108         /* fail safe */
109         st->cur_ptr = NULL;
110         st->cur_len = 0;
111 #else
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;
117 #endif
118
119         st->probe_packets = MAX_PROBE_PACKETS;
120 #endif
121
122         for(j=0; j<MAX_REORDER_DELAY+1; j++)
123             st->pts_buffer[j]= AV_NOPTS_VALUE;
124     }
125 }
126 #endif /* (defined USE_EXTERNAL_FFMPEG) */