/*
* DEMUXER v2.5
*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "config.h"
#include "options.h"
#include "talloc.h"
#include "mp_msg.h"
#include "m_config.h"
#include "libvo/fastmemcpy.h"
#include "stream/stream.h"
#include "demuxer.h"
#include "stheader.h"
#include "mf.h"
#include "libaf/af_format.h"
#include "libavcodec/avcodec.h"
#if MP_INPUT_BUFFER_PADDING_SIZE < FF_INPUT_BUFFER_PADDING_SIZE
#error MP_INPUT_BUFFER_PADDING_SIZE is too small!
#endif
static void clear_parser(sh_common_t *sh);
// Demuxer list
extern const struct demuxer_desc demuxer_desc_edl;
extern const struct demuxer_desc demuxer_desc_cue;
extern const demuxer_desc_t demuxer_desc_rawaudio;
extern const demuxer_desc_t demuxer_desc_rawvideo;
extern const demuxer_desc_t demuxer_desc_tv;
extern const demuxer_desc_t demuxer_desc_mf;
extern const demuxer_desc_t demuxer_desc_avi;
extern const demuxer_desc_t demuxer_desc_asf;
extern const demuxer_desc_t demuxer_desc_real;
extern const demuxer_desc_t demuxer_desc_matroska;
extern const demuxer_desc_t demuxer_desc_realaudio;
extern const demuxer_desc_t demuxer_desc_vivo;
extern const demuxer_desc_t demuxer_desc_gif;
extern const demuxer_desc_t demuxer_desc_avs;
extern const demuxer_desc_t demuxer_desc_rawdv;
extern const demuxer_desc_t demuxer_desc_audio;
extern const demuxer_desc_t demuxer_desc_rtp;
extern const demuxer_desc_t demuxer_desc_rtp_nemesi;
extern const demuxer_desc_t demuxer_desc_lavf;
extern const demuxer_desc_t demuxer_desc_lavf_preferred;
extern const demuxer_desc_t demuxer_desc_mng;
/* Please do not add any new demuxers here. If you want to implement a new
* demuxer, add it to libavformat, except for wrappers around external
* libraries and demuxers requiring binary support. */
const demuxer_desc_t *const demuxer_list[] = {
&demuxer_desc_edl,
&demuxer_desc_cue,
&demuxer_desc_rawaudio,
&demuxer_desc_rawvideo,
#ifdef CONFIG_TV
&demuxer_desc_tv,
#endif
&demuxer_desc_mf,
&demuxer_desc_lavf_preferred,
&demuxer_desc_avi,
&demuxer_desc_asf,
&demuxer_desc_matroska,
&demuxer_desc_realaudio,
#ifdef CONFIG_GIF
&demuxer_desc_gif,
#endif
#ifdef CONFIG_WIN32DLL
&demuxer_desc_avs,
#endif
&demuxer_desc_audio,
#ifdef CONFIG_LIVE555
&demuxer_desc_rtp,
#endif
#ifdef CONFIG_LIBNEMESI
&demuxer_desc_rtp_nemesi,
#endif
&demuxer_desc_lavf,
#ifdef CONFIG_LIBDV095
&demuxer_desc_rawdv,
#endif
#ifdef CONFIG_MNG
&demuxer_desc_mng,
#endif
/* Please do not add any new demuxers here. If you want to implement a new
* demuxer, add it to libavformat, except for wrappers around external
* libraries and demuxers requiring binary support. */
NULL
};
static struct demux_packet *create_packet(size_t len)
{
if (len > 1000000000) {
mp_msg(MSGT_DEMUXER, MSGL_FATAL, "Attempt to allocate demux packet "
"over 1 GB!\n");
abort();
}
struct demux_packet *dp = malloc(sizeof(struct demux_packet));
dp->len = len;
dp->next = NULL;
dp->pts = MP_NOPTS_VALUE;
dp->duration = -1;
dp->stream_pts = MP_NOPTS_VALUE;
dp->pos = 0;
dp->keyframe = false;
dp->refcount = 1;
dp->master = NULL;
dp->buffer = NULL;
dp->avpacket = NULL;
return dp;
}
struct demux_packet *new_demux_packet(size_t len)
{
struct demux_packet *dp = create_packet(len);
dp->buffer = malloc(len + MP_INPUT_BUFFER_PADDING_SIZE);
if (!dp->buffer) {
mp_msg(MSGT_DEMUXER, MSGL_FATAL, "Memory allocation failure!\n");
abort();
}
memset(dp->buffer + len, 0, 8);
return dp;
}
// data must already have suitable padding
struct demux_packet *new_demux_packet_fromdata(void *data, size_t len)
{
struct demux_packet *dp = create_packet(len);
dp->buffer = data;
return dp;
}
void resize_demux_packet(struct demux_packet *dp, size_t len)
{
if (len > 1000000000) {
mp_msg(MSGT_DEMUXER, MSGL_FATAL, "Attempt to realloc demux packet "
"over 1 GB!\n");
abort();
}
dp->buffer = realloc(dp->buffer, len + MP_INPUT_BUFFER_PADDING_SIZE);
if (!dp->buffer) {
mp_msg(MSGT_DEMUXER, MSGL_FATAL, "Memory allocation failure!\n");
abort();
}
memset(dp->buffer + len, 0, 8);
dp->len = len;
}
struct demux_packet *clone_demux_packet(struct demux_packet *pack)
{
struct demux_packet *dp = malloc(sizeof(struct demux_packet));
while (pack->master)
pack = pack->master; // find the master
memcpy(dp, pack, sizeof(struct demux_packet));
dp->next = N
|