Changeset 091069f in git


Ignore:
Timestamp:
19/06/11 12:20:40 (8 years ago)
Author:
Olly Betts <olly@…>
Branches:
add-show-splays, line_contents, master, stereo, svn/github/master, svn/origin/master, svn/tags/1.2.0, svn/tags/1.2.1, svn/tags/1.2.2, svn/tags/1.2.3, svn/tags/1.2.4, svn/tags/1.2.5, svn/trunk, travis-osx
Children:
c293aa9
Parents:
6ed625e
Message:

src/: Try to report errors from generating movie more helpfully.

git-svn-id: file:///home/survex-svn/survex/trunk@3622 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r6ed625e r091069f  
     1Sun Jun 19 11:19:51 GMT 2011  Olly Betts <olly@survex.com>
     2
     3        * src/: Try to report errors from generating movie more helpfully.
     4
    15Fri Jun 17 06:33:38 GMT 2011  Olly Betts <olly@survex.com>
    26
  • src/gfxcore.cc

    r6ed625e r091069f  
    55//
    66//  Copyright (C) 2000-2003,2005,2006 Mark R. Shinwell
    7 //  Copyright (C) 2001-2003,2004,2005,2006,2007,2010 Olly Betts
     7//  Copyright (C) 2001-2003,2004,2005,2006,2007,2010,2011 Olly Betts
    88//  Copyright (C) 2005 Martin Green
    99//
     
    28832883    // save to a Unicode path on wxmsw.
    28842884    if (!movie->Open(fnm.mb_str(), width, height)) {
    2885         // FIXME : sort out reporting actual errors from ffmpeg library
    2886         wxGetApp().ReportError(wxString::Format(wmsg(/*Error writing to file `%s'*/110), fnm.c_str()));
     2885        wxGetApp().ReportError(wxString(movie->get_error_string(), wxConvUTF8));
    28872886        delete movie;
    28882887        movie = 0;
  • src/mainfrm.cc

    r6ed625e r091069f  
    21792179                     wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
    21802180    if (dlg.ShowModal() == wxID_OK) {
    2181         if (!m_Gfx->ExportMovie(dlg.GetPath())) {
    2182             wxGetApp().ReportError(wxString::Format(wmsg(/*Error writing to file `%s'*/110), dlg.GetPath().c_str()));
    2183         }
     2181        // Error is reported by GfxCore.
     2182        (void)m_Gfx->ExportMovie(dlg.GetPath());
    21842183    }
    21852184}
  • src/moviemaker.cc

    r6ed625e r091069f  
    44//  Class for writing movies from Aven.
    55//
    6 //  Copyright (C) 2004 Olly Betts
     6//  Copyright (C) 2004,2011 Olly Betts
    77//
    88//  This program is free software; you can redistribute it and/or modify
     
    6969#endif
    7070
     71enum {
     72    MOVIE_NO_SUITABLE_FORMAT = 1,
     73    MOVIE_AUDIO_ONLY,
     74    MOVIE_FILENAME_TOO_LONG,
     75    MOVIE_NOT_ENABLED
     76};
     77
    7178const int OUTBUF_SIZE = 200000;
    7279
    7380MovieMaker::MovieMaker()
    74     : oc(0), st(0), frame(0), outbuf(0), pixels(0), sws_ctx(0)
     81    : oc(0), st(0), frame(0), outbuf(0), pixels(0), sws_ctx(0), averrno(0)
    7582{
    7683#ifdef HAVE_LIBAVFORMAT_AVFORMAT_H
     
    94101        fmt = guess_format("mpeg", NULL, NULL);
    95102        if (!fmt) {
    96             // FIXME : error finding a format...
     103            averrno = MOVIE_NO_SUITABLE_FORMAT;
    97104            return false;
    98105        }
    99106    }
    100107    if (fmt->video_codec == CODEC_ID_NONE) {
    101         // FIXME : The user asked for a format which is audio-only!
     108        averrno = MOVIE_AUDIO_ONLY;
    102109        return false;
    103110    }
     
    106113    oc = avformat_alloc_context();
    107114    if (!oc) {
    108         // FIXME : out of memory
     115        averrno = AVERROR_NOMEM;
    109116        return false;
    110117    }
    111118    oc->oformat = fmt;
    112119    if (strlen(fnm) >= sizeof(oc->filename)) {
    113         // FIXME : filename too long
     120        averrno = MOVIE_FILENAME_TOO_LONG;
    114121        return false;
    115122    }
     
    119126    st = av_new_stream(oc, 0);
    120127    if (!st) {
    121         // FIXME : possible errors are "too many streams" (can't be - we only
    122         // ask for one) and "out of memory"
     128        averrno = AVERROR_NOMEM;
    123129        return false;
    124130    }
     
    145151
    146152    // Set the output parameters (must be done even if no parameters).
    147     if (av_set_parameters(oc, NULL) < 0) {
    148         // FIXME : return value is an AVERROR_* value - probably
    149         // AVERROR_NOMEM or AVERROR_UNKNOWN.
     153    int retval = av_set_parameters(oc, NULL);
     154    if (retval < 0) {
     155        averrno = retval;
    150156        return false;
    151157    }
     
    160166        return false;
    161167    }
    162     if (avcodec_open(c, codec) < 0) {
    163         // FIXME : return value is an AVERROR_* value - probably
    164         // AVERROR_NOMEM or AVERROR_UNKNOWN.
     168
     169    retval = avcodec_open(c, codec);
     170    if (retval < 0) {
     171        averrno = retval;
    165172        return false;
    166173    }
     
    171178        outbuf = (unsigned char *)malloc(OUTBUF_SIZE);
    172179        if (!outbuf) {
    173             // FIXME : out of memory
     180            averrno = AVERROR_NOMEM;
    174181            return false;
    175182        }
     
    178185    frame = avcodec_alloc_frame();
    179186    if (!frame) {
    180         // FIXME : out of memory
     187        averrno = AVERROR_NOMEM;
    181188        return false;
    182189    }
     
    185192    if (!picture_buf) {
    186193        av_free(frame);
    187         // FIXME : out of memory
     194        averrno = AVERROR_NOMEM;
    188195        return false;
    189196    }
     
    198205    pixels = (unsigned char *)malloc(width * height * 6);
    199206    if (!pixels) {
    200         // FIXME : out of memory
    201         return false;
    202     }
    203 
    204     if (url_fopen(&oc->pb, fnm, URL_WRONLY) < 0) {
    205         // FIXME : return value is -E* (e.g. -EIO).
     207        averrno = AVERROR_NOMEM;
     208        return false;
     209    }
     210
     211    retval = url_fopen(&oc->pb, fnm, URL_WRONLY);
     212    if (retval < 0) {
     213        averrno = retval;
    206214        return false;
    207215    }
    208216
    209217    // Write the stream header, if any.
    210     if (av_write_header(oc) < 0) {
    211         // FIXME : return value is an AVERROR_* value.
     218    retval = av_write_header(oc);
     219    if (retval < 0) {
     220        averrno = retval;
    212221        return false;
    213222    }
     
    222231    }
    223232
     233    averrno = 0;
    224234    return true;
    225235#else
     236    averrno = MOVIE_NOT_ENABLED;
    226237    return false;
    227238#endif
     
    309320{
    310321#ifdef HAVE_LIBAVFORMAT_AVFORMAT_H
    311     if (st) {
     322    if (st && averrno == 0) {
    312323        // No more frames to compress.  The codec may have a few frames
    313324        // buffered if we're using B frames, so write those too.
     
    337348
    338349        av_write_trailer(oc);
    339 
     350    }
     351
     352    if (st) {
    340353        // Close codec.
    341         avcodec_close(c);
     354        avcodec_close(st->codec);
    342355    }
    343356
     
    367380#endif
    368381}
     382
     383const char *
     384MovieMaker::get_error_string() const
     385{
     386    switch (averrno) {
     387        case AVERROR_IO:
     388            return "I/O error";
     389        case AVERROR_NUMEXPECTED:
     390            return "Number syntax expected in filename";
     391        case AVERROR_INVALIDDATA:
     392            /* same as AVERROR_UNKNOWN: return "unknown error"; */
     393            return "invalid data found";
     394        case AVERROR_NOMEM:
     395            return "not enough memory";
     396        case AVERROR_NOFMT:
     397            return "unknown format";
     398        case AVERROR_NOTSUPP:
     399            return "Operation not supported";
     400        case AVERROR_NOENT:
     401            return "No such file or directory";
     402        case AVERROR_EOF:
     403            return "End of file";
     404        case AVERROR_PATCHWELCOME:
     405            return "Not implemented in FFmpeg";
     406        case 0:
     407            return "No error";
     408        case MOVIE_NO_SUITABLE_FORMAT:
     409            return "Couldn't find a suitable output format";
     410        case MOVIE_AUDIO_ONLY:
     411            return "Audio-only format specified";
     412        case MOVIE_FILENAME_TOO_LONG:
     413            return "Filename too long";
     414        case MOVIE_NOT_ENABLED:
     415            return "Movie export support not included";
     416    }
     417    return "Unknown error";
     418}
  • src/moviemaker.h

    r6ed625e r091069f  
    44//  Class for writing movies from Aven.
    55//
    6 //  Copyright (C) 2004,2010 Olly Betts
     6//  Copyright (C) 2004,2010,2011 Olly Betts
    77//
    88//  This program is free software; you can redistribute it and/or modify
     
    3636    unsigned char *pixels;
    3737    SwsContext *sws_ctx;
     38    int averrno;
    3839 
    3940public:
     
    4546    void AddFrame();
    4647    ~MovieMaker();
     48    const char * get_error_string() const;
    4749};
Note: See TracChangeset for help on using the changeset viewer.