MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / of_add_attachments

Function of_add_attachments

fftools/ffmpeg_mux_init.c:1902–1983  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1900}
1901
1902static int of_add_attachments(Muxer *mux, const OptionsContext *o)
1903{
1904 MuxStream *ms;
1905 OutputStream *ost;
1906 int err;
1907
1908 for (int i = 0; i < o->nb_attachments; i++) {
1909 AVIOContext *pb;
1910 uint8_t *attachment;
1911 char *attachment_filename;
1912 const char *p;
1913 int64_t len;
1914
1915 if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) {
1916 av_log(mux, AV_LOG_FATAL, "Could not open attachment file %s.\n",
1917 o->attachments[i]);
1918 return err;
1919 }
1920 if ((len = avio_size(pb)) <= 0) {
1921 av_log(mux, AV_LOG_FATAL, "Could not get size of the attachment %s.\n",
1922 o->attachments[i]);
1923 err = len ? len : AVERROR_INVALIDDATA;
1924 goto read_fail;
1925 }
1926 if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
1927 av_log(mux, AV_LOG_FATAL, "Attachment %s too large.\n",
1928 o->attachments[i]);
1929 err = AVERROR(ERANGE);
1930 goto read_fail;
1931 }
1932
1933 attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE);
1934 if (!attachment) {
1935 err = AVERROR(ENOMEM);
1936 goto read_fail;
1937 }
1938
1939 err = avio_read(pb, attachment, len);
1940 if (err < 0)
1941 av_log(mux, AV_LOG_FATAL, "Error reading attachment file %s: %s\n",
1942 o->attachments[i], av_err2str(err));
1943 else if (err != len) {
1944 av_log(mux, AV_LOG_FATAL, "Could not read all %"PRId64" bytes for "
1945 "attachment file %s\n", len, o->attachments[i]);
1946 err = AVERROR(EIO);
1947 }
1948
1949read_fail:
1950 avio_closep(&pb);
1951 if (err < 0)
1952 return err;
1953
1954 memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
1955
1956 av_log(mux, AV_LOG_VERBOSE, "Creating attachment stream from file %s\n",
1957 o->attachments[i]);
1958
1959 attachment_filename = av_strdup(o->attachments[i]);

Callers 1

create_streamsFunction · 0.85

Calls 12

avio_open2Function · 0.85
av_logFunction · 0.85
avio_sizeFunction · 0.85
avio_readFunction · 0.85
avio_closepFunction · 0.85
av_strdupFunction · 0.85
ost_addFunction · 0.85
av_freepFunction · 0.85
ms_from_ostFunction · 0.85
av_dict_setFunction · 0.85
av_mallocFunction · 0.50
av_freeFunction · 0.50

Tested by

no test coverage detected