Skip to content

Commit

Permalink
add AudioFrame.duration() for convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Feb 6, 2016
1 parent ead419a commit 1bdcad8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/AudioFrame.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2015 Wang Bin <[email protected]>
Copyright (C) 2012-2016 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -189,6 +189,12 @@ void AudioFrame::setAudioResampler(AudioResampler *conv)
d_func()->conv = conv;
}

qint64 AudioFrame::duration() const
{
Q_D(const AudioFrame);
return d->format.durationForBytes(d->data.size());
}

AudioFrame AudioFrame::to(const AudioFormat &fmt) const
{
if (!isValid() || !constBits(0))
Expand Down
9 changes: 8 additions & 1 deletion src/QtAV/AudioFrame.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2015 Wang Bin <[email protected]>
Copyright (C) 2012-2016 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -70,6 +70,13 @@ class Q_AV_EXPORT AudioFrame : public Frame
AudioFrame to(const AudioFormat& fmt) const;
//AudioResamplerId
void setAudioResampler(AudioResampler *conv); //TODO: remove
/*!
Returns the number of microseconds represented by \a bytes in this format.
Returns 0 if this format is not valid.
Note that some rounding may occur if \a bytes is not an exact multiple
of the number of bytes per frame.
*/
qint64 duration() const;
};

} //namespace QtAV
Expand Down

0 comments on commit 1bdcad8

Please sign in to comment.