Пример #1
0
void set_context_opts(void *ctx, void *opts_ctx, int flags, AVCodec *codec)
{
    int i;
    void *priv_ctx=NULL;
    if(!strcmp("AVCodecContext", (*(AVClass**)ctx)->class_name)){
        AVCodecContext *avctx= ctx;
        if(codec && codec->priv_class && avctx->priv_data){
            priv_ctx= avctx->priv_data;
        }
    } else if (!strcmp("AVFormatContext", (*(AVClass**)ctx)->class_name)) {
        AVFormatContext *avctx = ctx;
        if (avctx->oformat && avctx->oformat->priv_class) {
            priv_ctx = avctx->priv_data;
        }
    }

    for(i=0; i<opt_name_count; i++){
        char buf[256];
        const AVOption *opt;
        const char *str= av_get_string(opts_ctx, opt_names[i], &opt, buf, sizeof(buf));
        /* if an option with name opt_names[i] is present in opts_ctx then str is non-NULL */
        if(str && ((opt->flags & flags) == flags))
            av_set_string3(ctx, opt_names[i], str, 1, NULL);
        /* We need to use a differnt system to pass options to the private context because
           it is not known which codec and thus context kind that will be when parsing options
           we thus use opt_values directly instead of opts_ctx */
        if(!str && priv_ctx && av_get_string(priv_ctx, opt_names[i], &opt, buf, sizeof(buf))){
            av_set_string3(priv_ctx, opt_names[i], opt_values[i], 1, NULL);
        }
    }
}
Пример #2
0
void set_context_opts(void *ctx, void *opts_ctx, int flags)
{
    int i;
    for(i=0; i<opt_name_count; i++){
        char buf[256];
        const AVOption *opt;
        const char *str= av_get_string(opts_ctx, opt_names[i], &opt, buf, sizeof(buf));
        /* if an option with name opt_names[i] is present in opts_ctx then str is non-NULL */
        if(str && ((opt->flags & flags) == flags))
            av_set_string3(ctx, opt_names[i], str, 1, NULL);
    }
}
Пример #3
0
void set_context_opts(void *ctx, void *opts_ctx, int flags, AVCodec *codec)
{
    int i;
    void *priv_ctx=NULL;
    if(!strcmp("AVCodecContext", (*(AVClass**)ctx)->class_name)){
        AVCodecContext *avctx= ctx;
        if(codec && codec->priv_class && avctx->priv_data){
            priv_ctx= avctx->priv_data;
        }
    } else if (!strcmp("AVFormatContext", (*(AVClass**)ctx)->class_name)) {
        AVFormatContext *avctx = ctx;
        if (avctx->oformat && avctx->oformat->priv_class) {
            priv_ctx = avctx->priv_data;
        } else if (avctx->iformat && avctx->iformat->priv_class) {
            priv_ctx = avctx->priv_data;
        }
    }

    for(i=0; i<opt_name_count; i++){
        char buf[256];
        const AVOption *opt;
        const char *str;
        if (priv_ctx) {
            if (av_find_opt(priv_ctx, opt_names[i], NULL, flags, flags)) {
                if (av_set_string3(priv_ctx, opt_names[i], opt_values[i], 1, NULL) < 0) {
                    fprintf(stderr, "Invalid value '%s' for option '%s'\n",
                            opt_names[i], opt_values[i]);
                    exit(1);
                }
            } else
                goto global;
        } else {
        global:
            str = av_get_string(opts_ctx, opt_names[i], &opt, buf, sizeof(buf));
            /* if an option with name opt_names[i] is present in opts_ctx then str is non-NULL */
            if (str && ((opt->flags & flags) == flags))
                av_set_string3(ctx, opt_names[i], str, 1, NULL);
        }
    }
}
      db::MediaFile FileImporter::import(org::esb::io::File file) {
        db::HiveDb & connection = *getContext()->database; //("sqlite3", org::esb::config::Config::get("db.url"));
        db::MediaFile mediafile(connection);
        FormatInputStream fis(&file);
        if (!fis.isValid())return mediafile;
        connection.begin();
        PacketInputStream pis(&fis);
        //int id = 0;
        //  try {
        //    db::MediaFile mfile=litesql::select<db::MediaFile>(db, db::MediaFile::Path==file.getFilePath() && db::MediaFile::Filename==file.getFileName()).one();
        //    id=mfile.id;
        //  } catch (litesql::NotFound ex) {
        //org::esb::io::File tmpFile(file);
        mediafile.filename = file.getFileName();
        mediafile.path = file.getFilePath();
        mediafile.filesize = (double) fis.getFileSize();
        mediafile.streamcount = fis.getStreamCount();
        mediafile.containertype = fis.getFormatContext()->iformat->name;
        mediafile.duration = (double) fis.getFormatContext()->duration;
        mediafile.starttime = (double) fis.getFormatContext()->start_time;
        mediafile.bitrate = fis.getFormatContext()->bit_rate;
        mediafile.update();

        AVFormatContext *ctx = fis.getFormatContext();

        for (int a = 0; a < mediafile.streamcount; a++) {
          db::Stream stream(mediafile.getDatabase());
          stream.streamindex = (int) a;
          stream.streamtype = (int) ctx->streams[a]->codec->codec_type;
          stream.codecid = (int) ctx->streams[a]->codec->codec_id;
          stream.codecname = (const char*) ctx->streams[a]->codec->codec_name;
          stream.frameratenum = ctx->streams[a]->r_frame_rate.num;
          stream.framerateden = ctx->streams[a]->r_frame_rate.den;
          stream.firstpts = (double) ctx->streams[a]->start_time;
          stream.firstdts = (double) ctx->streams[a]->first_dts;
          stream.duration = (double) ctx->streams[a]->duration;
          stream.nbframes = (double) ctx->streams[a]->nb_frames;
          stream.streamtimebasenum = ctx->streams[a]->time_base.num;
          stream.streamtimebaseden = ctx->streams[a]->time_base.den;
          stream.codectimebasenum = ctx->streams[a]->codec->time_base.num;
          stream.codectimebaseden = ctx->streams[a]->codec->time_base.den;
          stream.ticksperframe = ctx->streams[a]->codec->ticks_per_frame;
          stream.width = ctx->streams[a]->codec->width;
          stream.height = ctx->streams[a]->codec->height;
          stream.gopsize = ctx->streams[a]->codec->gop_size;
          stream.pixfmt = (int) ctx->streams[a]->codec->pix_fmt;
          stream.bitrate = ctx->streams[a]->codec->bit_rate;
          stream.samplerate = ctx->streams[a]->codec->sample_rate;
          stream.samplefmt = (int) ctx->streams[a]->codec->sample_fmt;
          stream.channels = ctx->streams[a]->codec->channels;
          stream.bitspercodedsample = ctx->streams[a]->codec->bits_per_coded_sample;
          stream.extradatasize = 0;
          stream.extradatasize = ctx->streams[a]->codec->extradata_size;
          //          std::string data((char *)ctx->streams[a]->codec->extradata,ctx->streams[a]->codec->extradata_size);
          if (stream.extradatasize > 0)
            stream.extradata = litesql::Blob((char *) ctx->streams[a]->codec->extradata, ctx->streams[a]->codec->extradata_size);
          stream.update();
          const AVOption * option = NULL;
          int max_offset = 0;
          while (option = av_next_option(ctx->streams[a]->codec, option)) {
            if (option->offset > 0) {
              /*jump over depricated options*/
              if (strcmp(option->name, "lpc_coeff_precision") == 0 ||
                      strcmp(option->name, "prediction_order_method") == 0 ||
                      strcmp(option->name, "min_partition_order") == 0 ||
                      strcmp(option->name, "max_partition_order") == 0 ||
                      strcmp(option->name, "lpc_type") == 0 ||
                      strcmp(option->name, "drc_scale") == 0 ||
                      strcmp(option->name, "lpc_passes") == 0
                      )continue;
              max_offset = option->offset > max_offset ? option->offset : max_offset;
              db::StreamParameter sp(stream.getDatabase());
              sp.name = option->name;
              int len = 1000;
              char data[1000];
              memset(&data, 0, 1000);
              av_get_string(ctx->streams[a]->codec, option->name, NULL, data, len);
              if (strlen(data) > 0) {
                sp.val = std::string(data);
              }
              sp.update();
              stream.params().link(sp);
            }
          }
          LOGDEBUG("maxoffset=" << max_offset);
          db::StreamParameter sp(stream.getDatabase());
          sp.name = "codec_id";
          sp.val = org::esb::util::StringUtil::toString(ctx->streams[a]->codec->codec_id);
          sp.update();
          stream.params().link(sp);
          mediafile.streams().link(stream);
        }
        connection.commit();

        return mediafile;

      }