summaryrefslogtreecommitdiff
path: root/libavformat
Commit message (Collapse)AuthorAge
* lavf/tls_mbedtls: fix resource leakJun Zhao2020-04-22
| | | | | | | | fix resource leak in mbedtls part. fix #8614 Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
* avformat/matroskaenc: Use comparison instead of assignmentAndreas Rheinhardt2020-04-22
| | | | | | | This bug was introduced in 3589b3f2e217e78d16a92b372d95ce4a3f7df896. Fixes Coverity ID 1462425. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mpegtsenc: use the correct stream_types and write HDMV descriptors ↵Marton Balint2020-04-21
| | | | | | | | for m2ts Fixes ticket #2622. Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/mpegtsenc: factorize determining stream_typeMarton Balint2020-04-21
| | | | Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/mpegtsenc: only allow one program in m2ts modeMarton Balint2020-04-21
| | | | | | The standard does not allow more. Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/mpegtsenc: use standard pids for m2tsMarton Balint2020-04-21
| | | | Signed-off-by: Marton Balint <cus@passwd.hu>
* lavf/tls_gnutls: check for interrupt inside handshake loopBłażej Szczygieł2020-04-21
| | | | | | fixes #8080 Signed-off-by: Błażej Szczygieł <spaz16@wp.pl>
* avformat/matroskaenc: CosmeticsAndreas Rheinhardt2020-04-21
| | | | | | | | | | Reindentation, removal of { } if they contain only one statement and moving the return statement to a line of its own in situations like "if (ret < 0) return ret;". Moreover, several overlong lines were made shorter and a camelCase variable received a name in line with our naming conventions. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskaenc: Redo handling of FlagDefaultAndreas Rheinhardt2020-04-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Up until now, the Matroska muxer would mark a track as default if it had the disposition AV_DISPOSITION_DEFAULT or if there was no track with AV_DISPOSITION_DEFAULT set; in the latter case even more than one track of a kind (audio, video, subtitles) was marked as default which is not sensible. This commit changes the logic used to mark tracks as default. There are now three modes for this: a) In the "infer" mode the first track of every type (audio, video, subtitles) with default disposition set will be marked as default; if there is no such track (for a given type), then the first track of this type (if existing) will be marked as default. This behaviour is inspired by mkvmerge. It ensures that the default flags will be set in a sensible way even if the input comes from containers that lack the concept of default flags. This mode is the default mode. b) The "infer_no_subs" mode is similar to the "infer" mode; the difference is that if no subtitle track with default disposition exists, no subtitle track will be marked as default at all. c) The "passthrough" mode: Here the track will be marked as default if and only the corresponding input stream had disposition default. This fixes ticket #8173 (the passthrough mode is ideal for this) as well as ticket #8416 (the "infer_no_subs" mode leads to the desired output). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskaenc: Don't needlessly copy AVCodecParametersAndreas Rheinhardt2020-04-21
| | | | | | | | | | | | At the end of encoding, the FLAC encoder sends a packet whose side data contains updated extradata (e.g. a correct md5 checksum). The Matroska muxer uses this to update the CodecPrivate. In doing so, the stream's codecpar was copied. But given that writing a FLAC CodecPrivate does not modify the used AVCodecParameters at all, there is no need to do so and this commit changes this. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskaenc: Add const where appropriateAndreas Rheinhardt2020-04-21
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskaenc: Don't waste bytes on length fieldsAndreas Rheinhardt2020-04-21
| | | | | | | | | Several EBML Master elements for which a good upper bound of the final length was available were nevertheless written without giving an upper bound of the final length to start_ebml_master(), so that their length fields were eight bytes long. This has been changed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskaenc: Only write Tracks if there is a trackAndreas Rheinhardt2020-04-21
| | | | | | | | | | | The Matroska muxer does not write every stream as a Matroska track; some streams are written as AttachedFile. But should no stream be written as a Matroska track, the Matroska muxer would nevertheless write a Tracks element without a TrackEntry. This is against the spec. This commit changes this and only writes a Tracks if there is a Matroska track. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskaenc: Warn that WebM doesn't support AttachmentsAndreas Rheinhardt2020-04-21
| | | | | | | | As WebM doesn't support Attachments, the Matroska muxer drops them when in WebM mode. This happened silently until this commit which adds a warning for this. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskaenc: Don't use size of inexistent ClusterAndreas Rheinhardt2020-04-21
| | | | | | | | | | | | | | | | | | | In order to determine whether the current Cluster needs to be closed because of the limits on clustersize and clustertime, mkv_write_packet() would first get the size of the current Cluster by applying avio_tell() on the dynamic buffer holding the current Cluster. It did this without checking whether there is a dynamic buffer for writing Clusters open right now. In this case (which happens when writing the first packet) avio_tell() returned AVERROR(EINVAL); yet it is not good to rely on avio_tell() (or actually, avio_seek()) to handle the situation gracefully. Fixing this is easy: Only check whether a Cluster needs to be closed if a Cluster is in fact open. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskaenc: Add check for using explicit TrackNumberAndreas Rheinhardt2020-04-21
| | | | | | | | | | | When creating DASH streams, the TrackNumber is externally prescribed and not derived from the number of streams in the AVFormatContext, so if the number of tracks for a file using an explicit TrackNumber was more than one, the resulting file would be broken (it would be impossible to tell to which track a Block belongs if different tracks share the same TrackNumber). So disallow this. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskaenc: Improve Cues in case of no videoAndreas Rheinhardt2020-04-20
| | | | | | | | | | | | | | | | The Matroska muxer currently only adds CuePoints in three cases: a) For video keyframes. b) For the first audio frame in a new Cluster if in DASH-mode. c) For subtitles. This means that ordinary Matroska audio files won't have any Cues which impedes seeking. This commit changes this. For every track in a file without video track it is checked and tracked whether a Cue entry has already been added for said track for the current Cluster. This is used to add a Cue entry for each first packet of each track in each Cluster. Implements #3149. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskaenc: Remove limit on the number of tracksAndreas Rheinhardt2020-04-20
| | | | | | | | | | | | | | | The Matroska file format has practically no limit on the number of tracks (the current limit is 2^56 - 1); yet because they are encoded in a variable length format in (Simple)Blocks this muxer has simply imposed a limit on the number of tracks in order to ensure that they can always be written on one byte in order to simplify the muxing process. This commit removes said limit. Also, zero is an invalid TrackNumber, so disallow this value in the dash_track_number option. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskaenc: Refactor writing EBML lengthsAndreas Rheinhardt2020-04-20
| | | | | | | | This commit factors the ability to write ordinary EBML numbers out of the functions for writing EBML lengths. This is in preparation for future commits. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskaenc: Rename functions to better reflect what they doAndreas Rheinhardt2020-04-20
| | | | | | | | | | | | | | | | EBML uses variable length integers both for the EBML IDs as well as for the EBML lengths; Matroska also uses them for the TrackNumber in (Simple)Blocks and for the lengths of laces when EBML lacing is used. When encoding EBML lengths, certain encodings have a special meaning, namely that the element has an unknown length. This is not so when encoding general EBML variable length integers. Yet the functions called ebml_num_size() and put_ebml_num() had this special meaning hardcoded, i.e. they are there to write EBML lengths and not general EBML numbers. So rename them. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskaenc: Make ebml_num_size() more robustAndreas Rheinhardt2020-04-20
| | | | | | | | | | | | | | | | | | | | | | Matroska (or actually EBML) uses variable-length numbers where only seven bits of every byte is usable for the length; the other bits encode the length of the variable-length number. So in order to find out how many bytes one needs to encode a given number one can use a loop like while (num >> 7 * bytes) bytes++; the Matroska muxer effectively did this. Yet it has a disadvantage: It is impossible for the result of a single right shift of an unsigned number with most significant bit set to be zero, because one can only shift by 0..(width - 1). On some architectures like x64 it is not even possible to do it with undefined right shifts in which case this leads to an infinite loop. This can be easily avoided by switching to a loop whose condition is (num >>= 7). The maximum value the so modified function can return is 10; any value > 8 is invalid and will now lead to an assert in put_ebml_num() or in start_ebml_master() (or actually in put_ebml_size_unknown()). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroska: Move mime_tag lists to matroskadecAndreas Rheinhardt2020-04-20
| | | | | | They are not used any more by the muxer. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskaenc: Improve mimetype searchAndreas Rheinhardt2020-04-20
| | | | | | | | | | | | | | | | Use the mime_types of the corresponding AVCodecDescriptor instead of tables specific to Matroska. The former are generally more encompassing: They contain every item of the current lists except "text/plain" for AV_CODEC_ID_TEXT and "binary" for AV_CODEC_ID_BIN_DATA. The former has been preserved by special-casing it while the latter is a hack added in c9212abf so that the demuxer (which uses the same tables) sets the appropriate CodecID for broken files ("binary" is not a correct mime type at all); using it for the muxer was a mistake. The correct mime type for AV_CODEC_ID_BIN_DATA is "application/octet-stream" and this is what one gets from the AVCodecDescriptor. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/dashenc: add missing startWithSap attribute to AdaptationSet elementsJames Almer2020-04-20
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/dashenc: add a PlaybackRate elementJames Almer2020-04-20
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/dashenc: add a maxSegmentDuration attribute to the ManifestJames Almer2020-04-20
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/oggenc: Don't free AVStream's priv_data, fix memleakAndreas Rheinhardt2020-04-20
| | | | | | | | | | | | | | | | | | For FLAC, Speex, Opus and VP8 the Ogg muxer allocates two buffers for building the headers: The first for extradata in an Ogg-specific format and the second contains a Vorbiscomment. These buffers are reachable via pointers in the corresponding AVStream's priv_data. If an error happens during building the headers, the AVStream's priv_data would be freed. This is pointless in general as it would be freed generically anyway, but here it is actively harmful: If the second of the aforementioned allocations fails, the first buffer would leak upon freeing priv_data. This commit stops freeing priv_data manually, which allows the muxer to properly clean up in the deinit function. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/utils: Fix memleak when decoding subtitle in find_stream_infoAndreas Rheinhardt2020-04-20
| | | | | | | | | | | | | | | | | avformat_find_stream_info() may decode some frames to get stream information. And when it does this for subtitles, the decoded subtitles leak. (Decoding subtitles was added in b1511e00f6fefde6cb31b2e17f7812cfac1c8bd6 for PGS subtitles. When PGS subtitles originate from a container that exports every segment as a packet of its own, no output will be generated when decoding a packet, because not enough input is available. Yet when used with PGS subtitles in the Matroska form a single packet contains enough data to generate output. Yet said output is not freed, hence this leak.) Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/rtsp: Put strings instead of pointers to strings into arrayAndreas Rheinhardt2020-04-20
| | | | | | | | | | | | | In this example, the difference in length between the shortest and longest string is three, so that not using pointers to strings saves space even on 32bit systems. Moreover, there is no need to use a sentinel here; it can be replaced with FF_ARRAY_ELEMS. Reviewed-by: Ross Nicholson <phunkyfish@gmail.com> Reviewed-by: Marton Balint <cus@passwd.hu> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/rtsp: Don't free uninitialized AVBPrintAndreas Rheinhardt2020-04-20
| | | | | | | | Fixes Coverity ID 1462307. Reviewed-by: Marton Balint <cus@passwd.hu> Reviewed-by: Ross Nicholson <phunkyfish@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/movenc: cosmeticsLimin Wang2020-04-20
| | | | | Signed-off-by: Limin Wang <lance.lmwang@gmail.com> Signed-off-by: Josh de Kock <josh@itanimul.li>
* lavf/utils: stop using deprecated av_codec_next()Josh de Kock2020-04-20
| | | | Signed-off-by: Josh de Kock <josh@itanimul.li>
* libavformat/rtsp: pass protocol options for udp multicastWolfgang Haupt2020-04-19
| | | | | | | Protocol options like buffer_size need to be passed to the underlying transport implementation for udp multicasts as well. Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/rtp: Pass sources and block filter addresses via sdp file for rtpphunkyfish2020-04-19
| | | | Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/mpc: Simplify cleanupAndreas Rheinhardt2020-04-19
| | | | | | | | | | Currently Musepack allocates an array that needs to be freed later in the demuxer's read_close-function; it is the sole reason for said function's existence. But it is unnecessary, because one can store this array in the stream's priv_data pointer, so that it will be freed generically. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskadec: Remove redundant setting of chapter titlesAndreas Rheinhardt2020-04-19
| | | | | | | | | Chapter titles are added to the chapter's metadata since 6cb6e159, yet since 012867f0 (the predecessor of) avpriv_new_chapter() already adds the title to the chapter's metadata. So setting it again in matroskadec.c is redundant and expensive. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/flacenc: Don't allocate updated streaminfo separatelyAndreas Rheinhardt2020-04-18
| | | | | | | It is a small buffer of a known, fixed size and so it should simply be put into the muxer's context. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/flacenc: Only update streaminfo if it has changedAndreas Rheinhardt2020-04-18
| | | | | | | | | | | | | | | | | | | An AVStream's codecpar is supposed to be filled by the caller before avformat_write_header(); if the CodecParameters change, the caller should signal this via packet side data, but not touch the AVStream's codecpar. The FLAC muxer checks for packet side data containing updated extradata, yet if nothing has arrived by the time the trailer is written, the already written extradata is overwritten by the very same extradata again, unless the output is unseekable, in which case a warning that the FLAC header can't be rewritten is emitted. This commit changes this by only trying to rewrite the extradata if a new streaminfo arrived via packet side data. Only then is a warning emitted in case the output is unseekable. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* libavformat/mux, mxfenc: Don't initialize unnecessarilyAndreas Rheinhardt2020-04-18
| | | | | | | | | | | When no packet could be output, the interleavement functions nevertheless initialized the packet destined for output (with the exception of the data and size fields, making the initialization pointless), although it will not be used at all. So remove the initializations. Reviewed-by: Marton Balint <cus@passwd.hu> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mux: Remove pointless timestamp backupsAndreas Rheinhardt2020-04-18
| | | | | | | | | | | | | write_packet() currently saves the original timestamps of the packet it got and restores them in case writing fails. This is unnecessary as we are no longer working directly with the user-supplied AVPacket here; and it is also pointless because the timestamps may already have been altered before write_packet(). So remove this and add a general comment to the function that timestamps may be modified; also remove a long outdated comment about side data. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mux: Don't modify packets we don't ownAndreas Rheinhardt2020-04-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The documentation of av_write_frame() explicitly states that the function doesn't take ownership of the packets sent to it; while av_write_frame() does not directly unreference the packets after having written them, it nevertheless modifies the packet in various ways: 1. The timestamps might be modified either by prepare_input_packet() or compute_muxer_pkt_fields(). 2. If a bitstream filter gets applied, it takes ownership of the reference and the side-data in the packet sent to it. In case of do_packet_auto_bsf(), the end result is that the returned packet contains the output of the last bsf in the chain. If an error happens, a blank packet will be returned; a packet may also simply not lead to any output (vp9_superframe). This also implies that side data needs to be really copied and can't be shared with the input packet. The method choosen here minimizes copying of data: When the input isn't refcounted and no bitstream filter is applied, the packet's data will not be copied. Notice that packets that contain uncoded frames are exempt from this because these packets are not owned by and returned to the user. This also moves unreferencing the packets containing uncoded frames to av_write_frame() in the noninterleaved codepath; in the interleaved codepath, these packets are already freed in av_interleaved_write_frame(), so that unreferencing the packets in write_uncoded_frame_internal() is no longer needed. It has been removed. Reviewed-by: Marton Balint <cus@passwd.hu> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mux: Remove redundant resettingAndreas Rheinhardt2020-04-18
| | | | | | | | | | | | | | Now that ff_interleave_add_packet() always returns blank packets, the input packet to ff_interleave_packet_per_dts() will always be blank on return as well (if supplied) and the same goes for interleave_packet() in mux.c. Document these facts and remove the redundant resetting that happened in av_interleaved_write_frame(). The last reference to the (long removed) destruct field that AVPackets once had has been removed as well when updating the documentation of ff_interleave_packet_per_dts(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mux: Fix leak when adding packet to interleavement queue failsAndreas Rheinhardt2020-04-18
| | | | | | | | | | | | | | When an error happened in ff_interleave_add_packet() when adding a packet to the packet queue, said packet would not be unreferenced in ff_interleave_add_packet(), but would be zeroed in av_interleaved_write_frame(), which results in a memleak. This has been fixed: ff_interleave_add_packet() now always unreferences the input packet on error; as a result, it always returns blank packets which has been documented. Relying on this a call to av_packet_unref() in ff_audio_rechunk_interleave() can be removed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mux: Fix leaks on error when writing noninterleaved uncoded framesAndreas Rheinhardt2020-04-18
| | | | | | | | | | | | | | | If writing uncoded frames in noninterleaved mode fails at the preparatory steps (i.e. before it reaches write_packet()), the packet would not be unreferenced and the frame would leak. This is fixed by unreferencing the packet in write_uncoded_frame_internal() instead. This also makes it possible to remove the unreferencing in write_packet() itself: In noninterleaved mode frames are now freed in write_uncoded_frame_internal(), while they are freed in interleaved mode when their containing packet gets unreferenced (like normal packets). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mux: Make uncoded frames av_packet_unref() compatibleAndreas Rheinhardt2020-04-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently uncoded frames (i.e. packets whose data actually points to an AVFrame) are not refcounted. As a consequence, calling av_packet_unref() on them will not free them, but may simply make sure that they leak by losing the pointer to the frame. This commit changes this by actually making uncoded frames refcounted. In order not to rely on sizeof(AVFrame) (which is not part of the public API and so must not be used here in libavformat) the packet's data is changed to a (padded) buffer containing just a pointer to an AVFrame. Said buffer is owned by an AVBuffer with a custom free function that frees the frame as well as the buffer. Thereby the pointer/the AVBuffer owns the AVFrame. Said ownership can actually be transferred by copying and resetting the pointer, as might happen when actually writing the uncoded frames in AVOutputFormat.write_uncoded_frame() (although currently no muxer makes use of this possibility). This makes packets containing uncoded frames compatible with av_packet_unref(). This already has three advantages in interleaved mode: 1. If an error happens at the preparatory steps (before the packet is put into the interleavement queue), the frame is properly freed. 2. If the trailer is never written, the frames still in the interleavement queue will now be properly freed by ff_packet_list_free(). 3. The custom code for moving the packet to the packet list in ff_interleave_add_packet() can be removed. It will also simplify fixing further memleaks in future commits. Suggested-by: Marton Balint <cus@passwd.hu> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/dashenc: fix typo in ProducerReferenceTime elementsJames Almer2020-04-15
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/movenc: remove call to av_copy_packet_side_data() when ↵James Almer2020-04-15
| | | | | | | | | | | | concatenating eac3 syncframes This generates a potential memory leak, and mixes side data from the last packet with other properties from the first. Keep all the properties from the first packet only in the output packet instead. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/dashdec: add attribute lang for audio and subtitle streamsSteven Liu2020-04-15
| | | | | | There should have language in the metadata of streams which show to user Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
* avformat/hlsenc: add hls_fmp4_init_resend optionSteven Liu2020-04-15
| | | | | | add option for resend init file after m3u8 refresh everytime. Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
* avformat/filmstripenc: Use ff_raw_write_packet()Andreas Rheinhardt2020-04-14
| | | | | | | | | The only difference of the currently used write_packet()-function to ff_raw_write_packet() is that the former also counts the number of frames. Yet doing so in the muxer itself is unnecessary as this is already done generically in write_packet() in libavformat/mux.c. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>