Skip to content

Commit

Permalink
decoder/encoder option: default is set qt property
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Jun 11, 2015
1 parent c2ab12e commit 62d5277
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 44 deletions.
15 changes: 7 additions & 8 deletions src/QtAV/AVDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,16 @@ class Q_AV_EXPORT AVDecoder : public QObject
// avcodec_open2
/*!
* \brief setOptions
* 1. Set options for AVCodecContext. if contains key "avcodec", use it's value as a hash to set. a value of hash type is ignored.
* libav's AVDictionary. we can ignore the flags used in av_dict_xxx because we can use hash api.
* In addition, av_dict is slow.
* empty value does nothing to current context if it is open, but will change AVDictionary options to null in next open.
* 1. If has key "avcodec", it's value (suboption, a hash or map) will be used to set AVCodecContext use av_opt_set and av_dict_set. A value of hash type is ignored.
* we can ignore the flags used in av_dict_xxx because we can use hash api.
* empty value does nothing to current context if it is open, but will clear AVDictionary in the next open.
* AVDictionary is used in avcodec_open2() and will not change unless user call setOptions().
* 2. Set properties for AVDecoder. Use AVDecoder::name() or lower case as a key to set properties. If key not found, assume key is "avcodec"
* 2. Set QObject properties for AVDecoder. Use AVDecoder::name() or lower case as a key to set properties. If key not found, assume key is "avcodec"
* 3. If no ket AVDecoder::name() found in the option, set key-value pairs as QObject property-value pairs.
* \param dict
* example:
* "avcodec": {"vismv":"pf"}, "vaapi":{"display":"DRM"}
* equals
* "vismv":"pf", "vaapi":{"display":"DRM"}
* "avcodec": {"vismv":"pf"}, "vaapi":{"display":"DRM"}, "copyMode": "ZeroCopy"
* means set avcodec context option vismv=>pf, VA-API display (qt property) to DRM when using VA-API, set copyMode (GPU decoders) property to ZeroCopy
*/
void setOptions(const QVariantHash &dict);
QVariantHash options() const;
Expand Down
10 changes: 5 additions & 5 deletions src/QtAV/AVEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ class Q_AV_EXPORT AVEncoder : public QObject
// avcodec_open2
/*!
* \brief setOptions
* 1. Set options for AVCodecContext if it's a ffmpeg codec. if contains key "avcodec", use it's value as a hash to set. a value of hash type is ignored.
* libav's AVDictionary. we can ignore the flags used in av_dict_xxx because we can use hash api.
* In addition, av_dict is slow.
* empty value does nothing to current context if it is open, but will change AVDictionary options to null in next open.
* 1. If has key "avcodec", it's value (suboption, a hash or map) will be used to set AVCodecContext use av_opt_set and av_dict_set. A value of hash type is ignored.
* we can ignore the flags used in av_dict_xxx because we can use hash api.
* empty value does nothing to current context if it is open, but will clear AVDictionary in the next open.
* AVDictionary is used in avcodec_open2() and will not change unless user call setOptions().
* 2. Set properties for AVEncoder. Use AVEncoder::name() or lower case as a key to set properties. If key not found, assume key is "avcodec"
* 2. Set QObject properties for AVEncoder. Use AVEncoder::name() or lower case as a key to set properties. If key not found, assume key is "avcodec"
* 3. If no ket AVEncoder::name() found in the option, set key-value pairs as QObject property-value pairs.
*/
void setOptions(const QVariantHash &dict);
QVariantHash options() const;
Expand Down
24 changes: 8 additions & 16 deletions src/codec/AVDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,11 @@ void AVDecoder::setOptions(const QVariantHash &dict)
return;
if (name() == "avcodec")
return;
QVariant opt;
QVariant opt(dict);
if (dict.contains(name()))
opt = dict.value(name());
else if (dict.contains(name().toLower()))
opt = dict.value(name().toLower());
else
return; // TODO: set property if no name() key found?
Internal::setOptionsForQObject(opt, this);
}

Expand All @@ -238,16 +236,13 @@ void AVDecoderPrivate::applyOptionsForDict()
}
if (options.isEmpty())
return;
qDebug("set AVCodecContext dict:");
// TODO: use QVariantMap only
QVariant opt(options);
if (options.contains("avcodec"))
opt = options.value("avcodec");
if (!options.contains("avcodec"))
return;
qDebug("set AVCodecContext dict:");
// workaround for VideoDecoderFFmpeg. now it does not call av_opt_set_xxx, so set here in dict
// TODO: wrong if opt is empty
//if (dict.contains("FFmpeg"))
// avcodec_dict.unite(dict.value("FFmpeg").toHash());
Internal::setOptionsToDict(opt, &dict);
Internal::setOptionsToDict(options.value("avcodec"), &dict);
}

void AVDecoderPrivate::applyOptionsForContext()
Expand All @@ -259,14 +254,11 @@ void AVDecoderPrivate::applyOptionsForContext()
return;
}
// TODO: use QVariantMap only
QVariant opt(options);
if (options.contains("avcodec"))
opt = options.value("avcodec");
if (!options.contains("avcodec"))
return;
// workaround for VideoDecoderFFmpeg. now it does not call av_opt_set_xxx, so set here in dict
// TODO: wrong if opt is empty
//if (dict.contains("FFmpeg"))
// avcodec_dict.unite(dict.value("FFmpeg").toHash());
Internal::setOptionsToFFmpegObj(opt, codec_ctx);
Internal::setOptionsToFFmpegObj(options.value("avcodec"), codec_ctx);
}

} //namespace QtAV
22 changes: 7 additions & 15 deletions src/codec/AVEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,11 @@ void AVEncoder::setOptions(const QVariantHash &dict)
return;
if (name() == "avcodec")
return;
QVariant opt;
QVariant opt(dict);
if (dict.contains(name()))
opt = dict.value(name());
else if (dict.contains(name().toLower()))
opt = dict.value(name().toLower());
else
return; // TODO: set property if no name() key found?
Internal::setOptionsForQObject(opt, this);
}

Expand All @@ -177,14 +175,11 @@ void AVEncoderPrivate::applyOptionsForDict()
return;
qDebug("set AVCodecContext dict:");
// TODO: use QVariantMap only
QVariant opt(options);
if (options.contains("avcodec"))
opt = options.value("avcodec");
if (!options.contains("avcodec"))
return;
// workaround for VideoDecoderFFmpeg. now it does not call av_opt_set_xxx, so set here in dict
// TODO: wrong if opt is empty
//if (dict.contains("FFmpeg"))
// avcodec_dict.unite(dict.value("FFmpeg").toHash());
Internal::setOptionsToDict(opt, &dict);
Internal::setOptionsToDict(options.value("avcodec"), &dict);
}

void AVEncoderPrivate::applyOptionsForContext()
Expand All @@ -196,14 +191,11 @@ void AVEncoderPrivate::applyOptionsForContext()
return;
}
// TODO: use QVariantMap only
QVariant opt(options);
if (options.contains("avcodec"))
opt = options.value("avcodec");
if (!options.contains("avcodec"))
return;
// workaround for VideoDecoderFFmpeg. now it does not call av_opt_set_xxx, so set here in dict
// TODO: wrong if opt is empty
//if (dict.contains("FFmpeg"))
// avcodec_dict.unite(dict.value("FFmpeg").toHash());
Internal::setOptionsToFFmpegObj(opt, avctx);
Internal::setOptionsToFFmpegObj(options.value("avcodec"), avctx);
}

} //namespace QtAV

0 comments on commit 62d5277

Please sign in to comment.