LCOV - code coverage report
Current view: top level - libavformat - mlvdec.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 213 310 68.7 %
Date: 2017-12-13 18:07:29 Functions: 10 12 83.3 %

          Line data    Source code
       1             : /*
       2             :  * Magic Lantern Video (MLV) demuxer
       3             :  * Copyright (c) 2014 Peter Ross
       4             :  *
       5             :  * This file is part of FFmpeg.
       6             :  *
       7             :  * FFmpeg is free software; you can redistribute it and/or
       8             :  * modify it under the terms of the GNU Lesser General Public
       9             :  * License as published by the Free Software Foundation; either
      10             :  * version 2.1 of the License, or (at your option) any later version.
      11             :  *
      12             :  * FFmpeg is distributed in the hope that it will be useful,
      13             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :  * Lesser General Public License for more details.
      16             :  *
      17             :  * You should have received a copy of the GNU Lesser General Public
      18             :  * License along with FFmpeg; if not, write to the Free Software
      19             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      20             :  */
      21             : 
      22             : /**
      23             :  * @file
      24             :  * Magic Lantern Video (MLV) demuxer
      25             :  */
      26             : 
      27             : #include "libavutil/eval.h"
      28             : #include "libavutil/imgutils.h"
      29             : #include "libavutil/intreadwrite.h"
      30             : #include "libavutil/rational.h"
      31             : #include "avformat.h"
      32             : #include "avio_internal.h"
      33             : #include "internal.h"
      34             : #include "riff.h"
      35             : 
      36             : #define MLV_VERSION "v2.0"
      37             : 
      38             : #define MLV_VIDEO_CLASS_RAW  1
      39             : #define MLV_VIDEO_CLASS_YUV  2
      40             : #define MLV_VIDEO_CLASS_JPEG 3
      41             : #define MLV_VIDEO_CLASS_H264 4
      42             : 
      43             : #define MLV_AUDIO_CLASS_WAV  1
      44             : 
      45             : #define MLV_CLASS_FLAG_DELTA 0x40
      46             : #define MLV_CLASS_FLAG_LZMA  0x80
      47             : 
      48             : typedef struct {
      49             :     AVIOContext *pb[101];
      50             :     int class[2];
      51             :     int stream_index;
      52             :     uint64_t pts;
      53             : } MlvContext;
      54             : 
      55        6130 : static int probe(AVProbeData *p)
      56             : {
      57        6131 :     if (AV_RL32(p->buf) == MKTAG('M','L','V','I') &&
      58           2 :         AV_RL32(p->buf + 4) >= 52 &&
      59           1 :         !memcmp(p->buf + 8, MLV_VERSION, 5))
      60           1 :         return AVPROBE_SCORE_MAX;
      61        6129 :     return 0;
      62             : }
      63             : 
      64           0 : static int check_file_header(AVIOContext *pb, uint64_t guid)
      65             : {
      66             :     unsigned int size;
      67             :     uint8_t version[8];
      68             : 
      69           0 :     avio_skip(pb, 4);
      70           0 :     size = avio_rl32(pb);
      71           0 :     if (size < 52)
      72           0 :         return AVERROR_INVALIDDATA;
      73           0 :     avio_read(pb, version, 8);
      74           0 :     if (memcmp(version, MLV_VERSION, 5) || avio_rl64(pb) != guid)
      75           0 :         return AVERROR_INVALIDDATA;
      76           0 :     avio_skip(pb, size - 24);
      77           0 :     return 0;
      78             : }
      79             : 
      80           7 : static void read_string(AVFormatContext *avctx, AVIOContext *pb, const char *tag, int size)
      81             : {
      82           7 :     char * value = av_malloc(size + 1);
      83           7 :     if (!value) {
      84           0 :         avio_skip(pb, size);
      85           0 :         return;
      86             :     }
      87             : 
      88           7 :     avio_read(pb, value, size);
      89           7 :     if (!value[0]) {
      90           2 :         av_free(value);
      91           2 :         return;
      92             :     }
      93             : 
      94           5 :     value[size] = 0;
      95           5 :     av_dict_set(&avctx->metadata, tag, value, AV_DICT_DONT_STRDUP_VAL);
      96             : }
      97             : 
      98           4 : static void read_uint8(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
      99             : {
     100           4 :     av_dict_set_int(&avctx->metadata, tag, avio_r8(pb), 0);
     101           4 : }
     102             : 
     103           6 : static void read_uint16(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
     104             : {
     105           6 :     av_dict_set_int(&avctx->metadata, tag, avio_rl16(pb), 0);
     106           6 : }
     107             : 
     108          23 : static void read_uint32(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
     109             : {
     110          23 :     av_dict_set_int(&avctx->metadata, tag, avio_rl32(pb), 0);
     111          23 : }
     112             : 
     113           2 : static void read_uint64(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
     114             : {
     115           2 :     av_dict_set_int(&avctx->metadata, tag, avio_rl64(pb), 0);
     116           2 : }
     117             : 
     118           1 : static int scan_file(AVFormatContext *avctx, AVStream *vst, AVStream *ast, int file)
     119             : {
     120           1 :     MlvContext *mlv = avctx->priv_data;
     121           1 :     AVIOContext *pb = mlv->pb[file];
     122             :     int ret;
     123          14 :     while (!avio_feof(pb)) {
     124             :         int type;
     125             :         unsigned int size;
     126          13 :         type = avio_rl32(pb);
     127          13 :         size = avio_rl32(pb);
     128          13 :         avio_skip(pb, 8); //timestamp
     129          13 :         if (size < 16)
     130           1 :             break;
     131          12 :         size -= 16;
     132          12 :         if (vst && type == MKTAG('R','A','W','I') && size >= 164) {
     133           1 :             vst->codecpar->width  = avio_rl16(pb);
     134           1 :             vst->codecpar->height = avio_rl16(pb);
     135           1 :             ret = av_image_check_size(vst->codecpar->width, vst->codecpar->height, 0, avctx);
     136           1 :             if (ret < 0)
     137           0 :                 return ret;
     138           1 :             if (avio_rl32(pb) != 1)
     139           0 :                 avpriv_request_sample(avctx, "raw api version");
     140           1 :             avio_skip(pb, 20); // pointer, width, height, pitch, frame_size
     141           1 :             vst->codecpar->bits_per_coded_sample = avio_rl32(pb);
     142           2 :             if (vst->codecpar->bits_per_coded_sample < 0 ||
     143           1 :                 vst->codecpar->bits_per_coded_sample > (INT_MAX - 7) / (vst->codecpar->width * vst->codecpar->height)) {
     144           0 :                 av_log(avctx, AV_LOG_ERROR,
     145             :                        "invalid bits_per_coded_sample %d (size: %dx%d)\n",
     146           0 :                        vst->codecpar->bits_per_coded_sample,
     147           0 :                        vst->codecpar->width, vst->codecpar->height);
     148           0 :                 return AVERROR_INVALIDDATA;
     149             :             }
     150           1 :             avio_skip(pb, 8 + 16 + 24); // black_level, white_level, xywh, active_area, exposure_bias
     151           1 :             if (avio_rl32(pb) != 0x2010100) /* RGGB */
     152           0 :                 avpriv_request_sample(avctx, "cfa_pattern");
     153           1 :             avio_skip(pb, 80); // calibration_illuminant1, color_matrix1, dynamic_range
     154           1 :             vst->codecpar->format    = AV_PIX_FMT_BAYER_RGGB16LE;
     155           1 :             vst->codecpar->codec_tag = MKTAG('B', 'I', 'T', 16);
     156           1 :             size -= 164;
     157          11 :         } else if (ast && type == MKTAG('W', 'A', 'V', 'I') && size >= 16) {
     158           0 :             ret = ff_get_wav_header(avctx, pb, ast->codecpar, 16, 0);
     159           0 :             if (ret < 0)
     160           0 :                 return ret;
     161           0 :             size -= 16;
     162          11 :         } else if (type == MKTAG('I','N','F','O')) {
     163           1 :             if (size > 0)
     164           0 :                 read_string(avctx, pb, "info", size);
     165           1 :             continue;
     166          10 :         } else if (type == MKTAG('I','D','N','T') && size >= 36) {
     167           1 :             read_string(avctx, pb, "cameraName", 32);
     168           1 :             read_uint32(avctx, pb, "cameraModel", "0x%"PRIx32);
     169           1 :             size -= 36;
     170           2 :             if (size >= 32) {
     171           1 :                 read_string(avctx, pb, "cameraSerial", 32);
     172           1 :                 size -= 32;
     173             :             }
     174           9 :         } else if (type == MKTAG('L','E','N','S') && size >= 48) {
     175           2 :             read_uint16(avctx, pb, "focalLength", "%i");
     176           2 :             read_uint16(avctx, pb, "focalDist", "%i");
     177           2 :             read_uint16(avctx, pb, "aperture", "%i");
     178           2 :             read_uint8(avctx, pb, "stabilizerMode", "%i");
     179           2 :             read_uint8(avctx, pb, "autofocusMode", "%i");
     180           2 :             read_uint32(avctx, pb, "flags", "0x%"PRIx32);
     181           2 :             read_uint32(avctx, pb, "lensID", "%"PRIi32);
     182           2 :             read_string(avctx, pb, "lensName", 32);
     183           2 :             size -= 48;
     184           4 :             if (size >= 32) {
     185           2 :                 read_string(avctx, pb, "lensSerial", 32);
     186           2 :                 size -= 32;
     187             :             }
     188           8 :         } else if (vst && type == MKTAG('V', 'I', 'D', 'F') && size >= 4) {
     189           1 :             uint64_t pts = avio_rl32(pb);
     190           2 :             ff_add_index_entry(&vst->index_entries, &vst->nb_index_entries, &vst->index_entries_allocated_size,
     191           1 :                                avio_tell(pb) - 20, pts, file, 0, AVINDEX_KEYFRAME);
     192           1 :             size -= 4;
     193           6 :         } else if (ast && type == MKTAG('A', 'U', 'D', 'F') && size >= 4) {
     194           0 :             uint64_t pts = avio_rl32(pb);
     195           0 :             ff_add_index_entry(&ast->index_entries, &ast->nb_index_entries, &ast->index_entries_allocated_size,
     196           0 :                                avio_tell(pb) - 20, pts, file, 0, AVINDEX_KEYFRAME);
     197           0 :             size -= 4;
     198           6 :         } else if (vst && type == MKTAG('W','B','A','L') && size >= 28) {
     199           1 :             read_uint32(avctx, pb, "wb_mode", "%"PRIi32);
     200           1 :             read_uint32(avctx, pb, "kelvin", "%"PRIi32);
     201           1 :             read_uint32(avctx, pb, "wbgain_r", "%"PRIi32);
     202           1 :             read_uint32(avctx, pb, "wbgain_g", "%"PRIi32);
     203           1 :             read_uint32(avctx, pb, "wbgain_b", "%"PRIi32);
     204           1 :             read_uint32(avctx, pb, "wbs_gm", "%"PRIi32);
     205           1 :             read_uint32(avctx, pb, "wbs_ba", "%"PRIi32);
     206           1 :             size -= 28;
     207           6 :         } else if (type == MKTAG('R','T','C','I') && size >= 20) {
     208             :             char str[32];
     209           1 :             struct tm time = { 0 };
     210           1 :             time.tm_sec    = avio_rl16(pb);
     211           1 :             time.tm_min    = avio_rl16(pb);
     212           1 :             time.tm_hour   = avio_rl16(pb);
     213           1 :             time.tm_mday   = avio_rl16(pb);
     214           1 :             time.tm_mon    = avio_rl16(pb);
     215           1 :             time.tm_year   = avio_rl16(pb);
     216           1 :             time.tm_wday   = avio_rl16(pb);
     217           1 :             time.tm_yday   = avio_rl16(pb);
     218           1 :             time.tm_isdst  = avio_rl16(pb);
     219           1 :             avio_skip(pb, 2);
     220           1 :             if (strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S", &time))
     221           1 :                 av_dict_set(&avctx->metadata, "time", str, 0);
     222           1 :             size -= 20;
     223           4 :         } else if (type == MKTAG('E','X','P','O') && size >= 16) {
     224           2 :             av_dict_set(&avctx->metadata, "isoMode", avio_rl32(pb) ? "auto" : "manual", 0);
     225           2 :             read_uint32(avctx, pb, "isoValue", "%"PRIi32);
     226           2 :             read_uint32(avctx, pb, "isoAnalog", "%"PRIi32);
     227           2 :             read_uint32(avctx, pb, "digitalGain", "%"PRIi32);
     228           2 :             size -= 16;
     229           4 :             if (size >= 8) {
     230           2 :                 read_uint64(avctx, pb, "shutterValue", "%"PRIi64);
     231           2 :                 size -= 8;
     232             :             }
     233           2 :         } else if (type == MKTAG('S','T','Y','L') && size >= 36) {
     234           1 :             read_uint32(avctx, pb, "picStyleId", "%"PRIi32);
     235           1 :             read_uint32(avctx, pb, "contrast", "%"PRIi32);
     236           1 :             read_uint32(avctx, pb, "sharpness", "%"PRIi32);
     237           1 :             read_uint32(avctx, pb, "saturation", "%"PRIi32);
     238           1 :             read_uint32(avctx, pb, "colortone", "%"PRIi32);
     239           1 :             read_string(avctx, pb, "picStyleName", 16);
     240           1 :             size -= 36;
     241           1 :         } else if (type == MKTAG('M','A','R','K')) {
     242           1 :         } else if (type == MKTAG('N','U','L','L')) {
     243           0 :         } else if (type == MKTAG('M','L','V','I')) { /* occurs when MLV and Mnn files are concatenated */
     244             :         } else {
     245           0 :             av_log(avctx, AV_LOG_INFO, "unsupported tag %s, size %u\n",
     246           0 :                    av_fourcc2str(type), size);
     247             :         }
     248          11 :         avio_skip(pb, size);
     249             :     }
     250           1 :     return 0;
     251             : }
     252             : 
     253           1 : static int read_header(AVFormatContext *avctx)
     254             : {
     255           1 :     MlvContext *mlv = avctx->priv_data;
     256           1 :     AVIOContext *pb = avctx->pb;
     257           1 :     AVStream *vst = NULL, *ast = NULL;
     258             :     int size, ret;
     259             :     unsigned nb_video_frames, nb_audio_frames;
     260             :     uint64_t guid;
     261             :     char guidstr[32];
     262             : 
     263           1 :     avio_skip(pb, 4);
     264           1 :     size = avio_rl32(pb);
     265           1 :     if (size < 52)
     266           0 :         return AVERROR_INVALIDDATA;
     267             : 
     268           1 :     avio_skip(pb, 8);
     269             : 
     270           1 :     guid = avio_rl64(pb);
     271           1 :     snprintf(guidstr, sizeof(guidstr), "0x%"PRIx64, guid);
     272           1 :     av_dict_set(&avctx->metadata, "guid", guidstr, 0);
     273             : 
     274           1 :     avio_skip(pb, 8); //fileNum, fileCount, fileFlags
     275             : 
     276           1 :     mlv->class[0] = avio_rl16(pb);
     277           1 :     mlv->class[1] = avio_rl16(pb);
     278             : 
     279           1 :     nb_video_frames = avio_rl32(pb);
     280           1 :     nb_audio_frames = avio_rl32(pb);
     281             : 
     282           2 :     if (nb_video_frames && mlv->class[0]) {
     283           1 :         vst = avformat_new_stream(avctx, NULL);
     284           1 :         if (!vst)
     285           0 :             return AVERROR(ENOMEM);
     286           1 :         vst->id = 0;
     287           1 :         vst->nb_frames = nb_video_frames;
     288           1 :         if ((mlv->class[0] & (MLV_CLASS_FLAG_DELTA|MLV_CLASS_FLAG_LZMA)))
     289           0 :             avpriv_request_sample(avctx, "compression");
     290           1 :         vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
     291           1 :         switch (mlv->class[0] & ~(MLV_CLASS_FLAG_DELTA|MLV_CLASS_FLAG_LZMA)) {
     292           1 :         case MLV_VIDEO_CLASS_RAW:
     293           1 :             vst->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
     294           1 :             break;
     295           0 :         case MLV_VIDEO_CLASS_YUV:
     296           0 :             vst->codecpar->format   = AV_PIX_FMT_YUV420P;
     297           0 :             vst->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
     298           0 :             vst->codecpar->codec_tag = 0;
     299           0 :             break;
     300           0 :         case MLV_VIDEO_CLASS_JPEG:
     301           0 :             vst->codecpar->codec_id = AV_CODEC_ID_MJPEG;
     302           0 :             vst->codecpar->codec_tag = 0;
     303           0 :             break;
     304           0 :         case MLV_VIDEO_CLASS_H264:
     305           0 :             vst->codecpar->codec_id = AV_CODEC_ID_H264;
     306           0 :             vst->codecpar->codec_tag = 0;
     307           0 :             break;
     308           0 :         default:
     309           0 :             avpriv_request_sample(avctx, "unknown video class");
     310             :         }
     311           0 :     }
     312             : 
     313           1 :     if (nb_audio_frames && mlv->class[1]) {
     314           0 :         ast = avformat_new_stream(avctx, NULL);
     315           0 :         if (!ast)
     316           0 :             return AVERROR(ENOMEM);
     317           0 :         ast->id = 1;
     318           0 :         ast->nb_frames = nb_audio_frames;
     319           0 :         if ((mlv->class[1] & MLV_CLASS_FLAG_LZMA))
     320           0 :             avpriv_request_sample(avctx, "compression");
     321           0 :         if ((mlv->class[1] & ~MLV_CLASS_FLAG_LZMA) != MLV_AUDIO_CLASS_WAV)
     322           0 :             avpriv_request_sample(avctx, "unknown audio class");
     323             : 
     324           0 :         ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     325           0 :         avpriv_set_pts_info(ast, 33, 1, ast->codecpar->sample_rate);
     326             :     }
     327             : 
     328           1 :     if (vst) {
     329             :        AVRational framerate;
     330           1 :        framerate.num = avio_rl32(pb);
     331           1 :        framerate.den = avio_rl32(pb);
     332           1 :        avpriv_set_pts_info(vst, 64, framerate.den, framerate.num);
     333             :     } else
     334           0 :        avio_skip(pb, 8);
     335             : 
     336           1 :     avio_skip(pb, size - 52);
     337             : 
     338             :     /* scan primary file */
     339           1 :     mlv->pb[100] = avctx->pb;
     340           1 :     ret = scan_file(avctx, vst, ast, 100);
     341           1 :     if (ret < 0)
     342           0 :         return ret;
     343             : 
     344             :     /* scan secondary files */
     345           1 :     if (strlen(avctx->filename) > 2) {
     346             :         int i;
     347           1 :         char *filename = av_strdup(avctx->filename);
     348             : 
     349           1 :         if (!filename)
     350           0 :             return AVERROR(ENOMEM);
     351             : 
     352           1 :         for (i = 0; i < 100; i++) {
     353           1 :             snprintf(filename + strlen(filename) - 2, 3, "%02d", i);
     354           1 :             if (avctx->io_open(avctx, &mlv->pb[i], filename, AVIO_FLAG_READ, NULL) < 0)
     355           1 :                 break;
     356           0 :             if (check_file_header(mlv->pb[i], guid) < 0) {
     357           0 :                 av_log(avctx, AV_LOG_WARNING, "ignoring %s; bad format or guid mismatch\n", filename);
     358           0 :                 ff_format_io_close(avctx, &mlv->pb[i]);
     359           0 :                 continue;
     360             :             }
     361           0 :             av_log(avctx, AV_LOG_INFO, "scanning %s\n", filename);
     362           0 :             ret = scan_file(avctx, vst, ast, i);
     363           0 :             if (ret < 0) {
     364           0 :                 av_log(avctx, AV_LOG_WARNING, "ignoring %s; %s\n", filename, av_err2str(ret));
     365           0 :                 ff_format_io_close(avctx, &mlv->pb[i]);
     366           0 :                 continue;
     367             :             }
     368             :         }
     369           1 :         av_free(filename);
     370             :     }
     371             : 
     372           1 :     if (vst)
     373           1 :         vst->duration = vst->nb_index_entries;
     374           1 :     if (ast)
     375           0 :         ast->duration = ast->nb_index_entries;
     376             : 
     377           1 :     if ((vst && !vst->nb_index_entries) || (ast && !ast->nb_index_entries)) {
     378           0 :         av_log(avctx, AV_LOG_ERROR, "no index entries found\n");
     379           0 :         return AVERROR_INVALIDDATA;
     380             :     }
     381             : 
     382           1 :     if (vst && ast)
     383           0 :         avio_seek(pb, FFMIN(vst->index_entries[0].pos, ast->index_entries[0].pos), SEEK_SET);
     384           1 :     else if (vst)
     385           1 :         avio_seek(pb, vst->index_entries[0].pos, SEEK_SET);
     386           0 :     else if (ast)
     387           0 :         avio_seek(pb, ast->index_entries[0].pos, SEEK_SET);
     388             : 
     389           1 :     return 0;
     390             : }
     391             : 
     392           2 : static int read_packet(AVFormatContext *avctx, AVPacket *pkt)
     393             : {
     394           2 :     MlvContext *mlv = avctx->priv_data;
     395             :     AVIOContext *pb;
     396           2 :     AVStream *st = avctx->streams[mlv->stream_index];
     397             :     int index, ret;
     398             :     unsigned int size, space;
     399             : 
     400           2 :     if (mlv->pts >= st->duration)
     401           1 :         return AVERROR_EOF;
     402             : 
     403           1 :     index = av_index_search_timestamp(st, mlv->pts, AVSEEK_FLAG_ANY);
     404           1 :     if (index < 0) {
     405           0 :         av_log(avctx, AV_LOG_ERROR, "could not find index entry for frame %"PRId64"\n", mlv->pts);
     406           0 :         return AVERROR(EIO);
     407             :     }
     408             : 
     409           1 :     pb = mlv->pb[st->index_entries[index].size];
     410           1 :     avio_seek(pb, st->index_entries[index].pos, SEEK_SET);
     411             : 
     412           1 :     avio_skip(pb, 4); // blockType
     413           1 :     size = avio_rl32(pb);
     414           1 :     if (size < 16)
     415           0 :         return AVERROR_INVALIDDATA;
     416           1 :     avio_skip(pb, 12); //timestamp, frameNumber
     417           1 :     if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
     418           1 :         avio_skip(pb, 8); // cropPosX, cropPosY, panPosX, panPosY
     419           1 :     space = avio_rl32(pb);
     420           1 :     avio_skip(pb, space);
     421             : 
     422           1 :     if ((mlv->class[st->id] & (MLV_CLASS_FLAG_DELTA|MLV_CLASS_FLAG_LZMA))) {
     423           0 :         ret = AVERROR_PATCHWELCOME;
     424           1 :     } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
     425           1 :         ret = av_get_packet(pb, pkt, (st->codecpar->width * st->codecpar->height * st->codecpar->bits_per_coded_sample + 7) >> 3);
     426             :     } else { // AVMEDIA_TYPE_AUDIO
     427           0 :         if (space > UINT_MAX - 24 || size < (24 + space))
     428           0 :             return AVERROR_INVALIDDATA;
     429           0 :         ret = av_get_packet(pb, pkt, size - (24 + space));
     430             :     }
     431             : 
     432           1 :     if (ret < 0)
     433           0 :         return ret;
     434             : 
     435           1 :     pkt->stream_index = mlv->stream_index;
     436           1 :     pkt->pts = mlv->pts;
     437             : 
     438           1 :     mlv->stream_index++;
     439           1 :     if (mlv->stream_index == avctx->nb_streams) {
     440           1 :         mlv->stream_index = 0;
     441           1 :         mlv->pts++;
     442             :     }
     443           1 :     return 0;
     444             : }
     445             : 
     446           0 : static int read_seek(AVFormatContext *avctx, int stream_index, int64_t timestamp, int flags)
     447             : {
     448           0 :     MlvContext *mlv = avctx->priv_data;
     449             : 
     450           0 :     if ((flags & AVSEEK_FLAG_FRAME) || (flags & AVSEEK_FLAG_BYTE))
     451           0 :         return AVERROR(ENOSYS);
     452             : 
     453           0 :     if (!(avctx->pb->seekable & AVIO_SEEKABLE_NORMAL))
     454           0 :         return AVERROR(EIO);
     455             : 
     456           0 :     mlv->pts = timestamp;
     457           0 :     return 0;
     458             : }
     459             : 
     460           1 : static int read_close(AVFormatContext *s)
     461             : {
     462           1 :     MlvContext *mlv = s->priv_data;
     463             :     int i;
     464         101 :     for (i = 0; i < 100; i++)
     465         100 :         if (mlv->pb[i])
     466           0 :             ff_format_io_close(s, &mlv->pb[i]);
     467           1 :     return 0;
     468             : }
     469             : 
     470             : AVInputFormat ff_mlv_demuxer = {
     471             :     .name           = "mlv",
     472             :     .long_name      = NULL_IF_CONFIG_SMALL("Magic Lantern Video (MLV)"),
     473             :     .priv_data_size = sizeof(MlvContext),
     474             :     .read_probe     = probe,
     475             :     .read_header    = read_header,
     476             :     .read_packet    = read_packet,
     477             :     .read_close     = read_close,
     478             :     .read_seek      = read_seek,
     479             : };

Generated by: LCOV version 1.13