Exemplo n.º 1
0
Codec*
Codec::guessEncodingCodec(MuxerFormat* pFmt, const char* shortName,
    const char* url, const char* mimeType, MediaDescriptor::Type type) {
  Global::init();
  Codec* retval = 0;
  RefPointer<MuxerFormat> fmt = 0;
  AVOutputFormat * oFmt = 0;

  // We acquire here because the RefPointer always
  // releases.
  fmt.reset(dynamic_cast<MuxerFormat*>(pFmt), true);

  if (!fmt) {
    fmt = MuxerFormat::guessFormat(shortName, url, mimeType);
  }
  if (fmt) oFmt = fmt->getCtx();

  // Make sure at least one in put is specified.
  // The av_guess_codec function REQUIRES a
  // non null AVOutputFormat
  // It also examines url with a strcmp(), so let's
  // give it a zero-length string.
  // In reality, it ignores the other params.
  if (!url) url = "";

  if (oFmt) {
    enum AVCodecID id = av_guess_codec(oFmt, shortName, url, mimeType,
        (enum AVMediaType) type);
    retval = Codec::findEncodingCodecByIntID((int) id);
  }
  return retval;
}
Exemplo n.º 2
0
void
Coder::open(KeyValueBag* inputOptions, KeyValueBag* aUnsetOptions) {
  int32_t retval = -1;
  AVDictionary* tmp=0;
  try {
      // Time to set options
    if (inputOptions) {
      KeyValueBagImpl* options = dynamic_cast<KeyValueBagImpl*>(inputOptions);
      // make a copy of the data returned.
      av_dict_copy(&tmp, options->getDictionary(), 0);
    }

    // first we're going to set options (and we'll set them again later)
    retval = av_opt_set_dict(mCtx, &tmp);
    FfmpegException::check(retval, "could not set options on coder");

    // we check that the options passed in our valid
    checkOptionsBeforeOpen();

    RefPointer<Codec> codec = getCodec();
    // we pass in the options again because codec-specific options can be set.
    retval = avcodec_open2(mCtx, codec->getCtx(), &tmp);
    FfmpegException::check(retval, "could not open codec");
    setState(STATE_OPENED);

    if (aUnsetOptions)
    {
      KeyValueBagImpl* unsetOptions = dynamic_cast<KeyValueBagImpl*>(aUnsetOptions);
      unsetOptions->copy(tmp);
    }
    if (tmp)
      av_dict_free(&tmp);
  } catch (...) {
    setState(STATE_ERROR);
    if (tmp)
      av_dict_free(&tmp);
    throw;
  }
}