*/
void ff_format_io_close(AVFormatContext *s, AVIOContext **pb);
+/**
+ * Parse creation_time in AVFormatContext metadata if exists and warn if the
+ * parsing fails.
+ *
+ * @param s AVFormatContext
+ * @param timestamp parsed timestamp in microseconds, only set on successful parsing
+ * @param return_seconds set this to get the number of seconds in timestamp instead of microseconds
+ * @return 1 if OK, 0 if the metadata was not present, AVERROR(EINVAL) on parse error
+ */
+int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds);
+
+/**
+ * Standardize creation_time metadata in AVFormatContext to an ISO-8601
+ * timestamp string.
+ *
+ * @param s AVFormatContext
+ * @return <0 on error
+ */
+int ff_standardize_creation_time(AVFormatContext *s);
+
+#define CONTAINS_PAL 2
+/**
+ * Reshuffles the lines to use the user specified stride.
+ *
+ * @param ppkt input and output packet
+ * @return negative error code or
+ * 0 if no new packet was allocated
+ * non-zero if a new packet was allocated and ppkt has to be freed
+ * CONTAINS_PAL if in addition to a new packet the old contained a palette
+ */
+int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecParameters *par, int expected_stride);
+
+/**
+ * Retrieves the palette from a packet, either from side data, or
+ * appended to the video data in the packet itself (raw video only).
+ * It is commonly used after a call to ff_reshuffle_raw_rgb().
+ *
+ * Use 0 for the ret parameter to check for side data only.
+ *
+ * @param pkt pointer to packet before calling ff_reshuffle_raw_rgb()
+ * @param ret return value from ff_reshuffle_raw_rgb(), or 0
+ * @param palette pointer to palette buffer
+ * @return negative error code or
+ * 1 if the packet has a palette, else 0
+ */
+int ff_get_packet_palette(AVFormatContext *s, AVPacket *pkt, int ret, uint32_t *palette);
+
+/**
+ * Finalize buf into extradata and set its size appropriately.
+ */
+int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf);
+
/**
* Find the next packet in the interleaving queue for the given stream.
- * The packet is not removed from the interleaving queue, but only
- * a pointer to it is returned.
+ * The pkt parameter is filled in with the queued packet, including
+ * references to the data (which the caller is not allowed to keep or
+ * modify).
*
- * @param ts_offset the ts difference between packet in the queue and the muxer.
- *
- * @return a pointer to the next packet, or NULL if no packet is queued
- * for this stream.
+ * @return 0 if a packet was found, a negative value if no packet was found
*/
- const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream, int64_t *ts_offset);
+ int ff_interleaved_peek(AVFormatContext *s, int stream,
+ AVPacket *pkt, int add_offset);
#endif /* AVFORMAT_INTERNAL_H */
* Those additional safety checks should be dropped once the correct checks
* are set in the callers.
*/
-
static int write_packet(AVFormatContext *s, AVPacket *pkt)
{
- int ret;
+ int ret, did_split;
+ int64_t pts_backup, dts_backup;
+
+ pts_backup = pkt->pts;
+ dts_backup = pkt->dts;
+
+ // If the timestamp offsetting below is adjusted, adjust
+ // ff_interleaved_peek similarly.
+ if (s->output_ts_offset) {
+ AVStream *st = s->streams[pkt->stream_index];
+ int64_t offset = av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base);
+
+ if (pkt->dts != AV_NOPTS_VALUE)
+ pkt->dts += offset;
+ if (pkt->pts != AV_NOPTS_VALUE)
+ pkt->pts += offset;
+ }
+
if (s->avoid_negative_ts > 0) {
- AVRational time_base = s->streams[pkt->stream_index]->time_base;
- int64_t offset = 0;
+ AVStream *st = s->streams[pkt->stream_index];
+ int64_t offset = st->mux_ts_offset;
+ int64_t ts = s->internal->avoid_negative_ts_use_pts ? pkt->pts : pkt->dts;
- if (s->internal->offset == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE &&
- (pkt->dts < 0 || s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO)) {
- s->internal->offset = -pkt->dts;
- s->internal->offset_timebase = time_base;
+ if (s->internal->offset == AV_NOPTS_VALUE && ts != AV_NOPTS_VALUE &&
+ (ts < 0 || s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO)) {
+ s->internal->offset = -ts;
+ s->internal->offset_timebase = st->time_base;
+ }
+
+ if (s->internal->offset != AV_NOPTS_VALUE && !offset) {
+ offset = st->mux_ts_offset =
+ av_rescale_q_rnd(s->internal->offset,
+ s->internal->offset_timebase,
+ st->time_base,
+ AV_ROUND_UP);
}
- if (s->internal->offset != AV_NOPTS_VALUE)
- offset = av_rescale_q(s->internal->offset, s->internal->offset_timebase, time_base);
if (pkt->dts != AV_NOPTS_VALUE)
pkt->dts += offset;
AVPacketList *pktl = s->internal->packet_buffer;
while (pktl) {
if (pktl->pkt.stream_index == stream) {
- AVPacket *pkt = &pktl->pkt;
- AVStream *st = s->streams[pkt->stream_index];
- *ts_offset = st->mux_ts_offset;
-
- if (s->output_ts_offset)
- *ts_offset += av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base);
-
- return pkt;
+ *pkt = pktl->pkt;
- if (add_offset && s->internal->offset != AV_NOPTS_VALUE) {
- int64_t offset = av_rescale_q(s->internal->offset,
- s->internal->offset_timebase,
- s->streams[stream]->time_base);
++ if (add_offset) {
++ AVStream *st = s->streams[pkt->stream_index];
++ int64_t offset = st->mux_ts_offset;
++
++ if (s->output_ts_offset)
++ offset += av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base);
++
+ if (pkt->dts != AV_NOPTS_VALUE)
+ pkt->dts += offset;
+ if (pkt->pts != AV_NOPTS_VALUE)
+ pkt->pts += offset;
+ }
+ return 0;
}
pktl = pktl->next;
}