1 /* 2 * This file is part of mpv. 3 * 4 * mpv is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * mpv is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with mpv. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef MPLAYER_DEMUX_PACKET_H 19 #define MPLAYER_DEMUX_PACKET_H 20 21 #include <stdbool.h> 22 #include <stddef.h> 23 #include <inttypes.h> 24 25 // Holds one packet/frame/whatever 26 typedef struct demux_packet { 27 double pts; 28 double dts; 29 double duration; 30 int64_t pos; // position in source file byte stream 31 32 union { 33 // Normally valid for packets. 34 struct { 35 unsigned char *buffer; 36 size_t len; 37 }; 38 39 // Used if is_cached==true, special uses only. 40 struct { 41 uint64_t pos; 42 } cached_data; 43 }; 44 45 int stream; // source stream index (typically sh_stream.index) 46 47 bool keyframe; 48 49 // backward playback 50 bool back_restart : 1; // restart point (reverse and return previous frames) 51 bool back_preroll : 1; // initial discarded frame for smooth decoder reinit 52 53 // If true, cached_data is valid, while buffer/len are not. 54 bool is_cached : 1; 55 56 // segmentation (ordered chapters, EDL) 57 bool segmented; 58 struct mp_codec_params *codec; // set to non-NULL iff segmented is set 59 double start, end; // set to non-NOPTS iff segmented is set 60 61 // private 62 struct demux_packet *next; 63 struct AVPacket *avpacket; // keep the buffer allocation and sidedata 64 uint64_t cum_pos; // demux.c internal: cumulative size until _start_ of pkt 65 } demux_packet_t; 66 67 struct AVBufferRef; 68 69 struct demux_packet *new_demux_packet(size_t len); 70 struct demux_packet *new_demux_packet_from_avpacket(struct AVPacket *avpkt); 71 struct demux_packet *new_demux_packet_from(void *data, size_t len); 72 struct demux_packet *new_demux_packet_from_buf(struct AVBufferRef *buf); 73 void demux_packet_shorten(struct demux_packet *dp, size_t len); 74 void free_demux_packet(struct demux_packet *dp); 75 struct demux_packet *demux_copy_packet(struct demux_packet *dp); 76 size_t demux_packet_estimate_total_size(struct demux_packet *dp); 77 78 void demux_packet_copy_attribs(struct demux_packet *dst, struct demux_packet *src); 79 80 int demux_packet_set_padding(struct demux_packet *dp, int start, int end); 81 int demux_packet_add_blockadditional(struct demux_packet *dp, uint64_t id, 82 void *data, size_t size); 83 84 void demux_packet_unref_contents(struct demux_packet *dp); 85 86 #endif /* MPLAYER_DEMUX_PACKET_H */ 87