Skip to content

Commit

Permalink
Rename Stream2, Frame2<T>, VideoFrame2 and AudioSamples2
Browse files Browse the repository at this point in the history
Remove 2 from the end and provide alias types.
  • Loading branch information
h4tr3d committed Apr 18, 2016
1 parent 32a6ace commit deef359
Show file tree
Hide file tree
Showing 24 changed files with 201 additions and 196 deletions.
4 changes: 2 additions & 2 deletions example/api2-samples/api2-decode-audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main(int argc, char **argv)

ssize_t audioStream = -1;
CodecContext adec;
Stream2 ast;
Stream ast;
error_code ec;

string format;
Expand Down Expand Up @@ -120,7 +120,7 @@ int main(int argc, char **argv)

clog << "Read packet: " << pkt.pts() << " / " << pkt.pts().seconds() << " / " << pkt.timeBase() << " / st: " << pkt.streamIndex() << endl;

AudioSamples2 samples = adec.decodeAudio(pkt, ec);
AudioSamples samples = adec.decodeAudio(pkt, ec);

if (ec) {
cerr << "Error: " << ec << endl;
Expand Down
10 changes: 5 additions & 5 deletions example/api2-samples/api2-decode-encode-audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main(int argc, char **argv)

ssize_t audioStream = -1;
CodecContext adec;
Stream2 ast;
Stream ast;
error_code ec;

int count = 0;
Expand Down Expand Up @@ -98,7 +98,7 @@ int main(int argc, char **argv)
octx.setFormat(ofmt);

Codec ocodec = av::findEncodingCodec(ofmt, false);
Stream2 ost = octx.addStream(ocodec);
Stream ost = octx.addStream(ocodec);
CodecContext enc (ost);

clog << ocodec.name() << " / " << ocodec.longName() << ", audio: " << (ocodec.type()==AVMEDIA_TYPE_AUDIO) << '\n';
Expand Down Expand Up @@ -202,7 +202,7 @@ int main(int argc, char **argv)
}
#endif

AudioSamples2 samples = adec.decodeAudio(pkt, ec);
AudioSamples samples = adec.decodeAudio(pkt, ec);
count++;
//if (count > 200)
// break;
Expand Down Expand Up @@ -241,7 +241,7 @@ int main(int argc, char **argv)
// Pop resampler data
bool getAll = !samples;
while (true) {
AudioSamples2 ouSamples(enc.sampleFormat(),
AudioSamples ouSamples(enc.sampleFormat(),
enc.frameSize(),
enc.channelLayout(),
enc.sampleRate());
Expand Down Expand Up @@ -301,7 +301,7 @@ int main(int argc, char **argv)
//
clog << "Flush encoder:\n";
while (true) {
AudioSamples2 null(nullptr);
AudioSamples null(nullptr);
Packet opkt = enc.encodeAudio(null, ec);
if (ec || !opkt)
break;
Expand Down
4 changes: 2 additions & 2 deletions example/api2-samples/api2-decode-encode-video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main(int argc, char **argv)
FormatContext ictx;
ssize_t videoStream = -1;
CodecContext vdec;
Stream2 vst;
Stream vst;

int count = 0;

Expand Down Expand Up @@ -88,7 +88,7 @@ int main(int argc, char **argv)
octx.setFormat(ofrmt);

Codec ocodec = findEncodingCodec(ofrmt);
Stream2 ost = octx.addStream(ocodec);
Stream ost = octx.addStream(ocodec);
CodecContext encoder {ost};

// Settings
Expand Down
10 changes: 5 additions & 5 deletions example/api2-samples/api2-decode-rasample-audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main(int argc, char **argv)

ssize_t audioStream = -1;
CodecContext adec;
Stream2 ast;
Stream ast;
error_code ec;

int count = 0;
Expand Down Expand Up @@ -114,7 +114,7 @@ int main(int argc, char **argv)

clog << "Read packet: " << pkt.pts() << " / " << pkt.pts().seconds() << " / " << pkt.timeBase() << " / st: " << pkt.streamIndex() << endl;

AudioSamples2 samples = adec.decodeAudio(pkt, ec);
AudioSamples samples = adec.decodeAudio(pkt, ec);

count++;
if (count > 100)
Expand Down Expand Up @@ -145,7 +145,7 @@ int main(int argc, char **argv)
// Pop resampler data
#if 0
while (true) {
AudioSamples2 ouSamples(adec.sampleFormat(), samples.samplesCount()/2, adec.channelLayout(), 48000);
AudioSamples ouSamples(adec.sampleFormat(), samples.samplesCount()/2, adec.channelLayout(), 48000);

// Resample:
//st = resampler.resample(ouSamples, samples);
Expand All @@ -165,7 +165,7 @@ int main(int argc, char **argv)
<< endl;
}
#else
auto ouSamples = AudioSamples2::null();
auto ouSamples = AudioSamples::null();
while (ouSamples = resampler.pop(samples.samplesCount()/2, ec)) {
clog << " Samples [ou]: " << ouSamples.samplesCount()
<< ", ch: " << ouSamples.channelsCount()
Expand All @@ -186,7 +186,7 @@ int main(int argc, char **argv)
{
clog << "Flush resampler:\n";
while (true) {
AudioSamples2 ouSamples(adec.sampleFormat(), 576, adec.channelLayout(), 48000);
AudioSamples ouSamples(adec.sampleFormat(), 576, adec.channelLayout(), 48000);
auto hasFrame = resampler.pop(ouSamples, false, ec);
if (!ec && !hasFrame)
hasFrame = resampler.pop(ouSamples, true, ec);
Expand Down
6 changes: 3 additions & 3 deletions example/api2-samples/api2-decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main(int argc, char **argv)

ssize_t videoStream = -1;
CodecContext vdec;
Stream2 vst;
Stream vst;
error_code ec;

int count = 0;
Expand Down Expand Up @@ -103,7 +103,7 @@ int main(int argc, char **argv)
auto ts = pkt.ts();
clog << "Read packet: " << ts << " / " << ts.seconds() << " / " << pkt.timeBase() << " / st: " << pkt.streamIndex() << endl;

VideoFrame2 frame = vdec.decodeVideo(pkt, ec);
VideoFrame frame = vdec.decodeVideo(pkt, ec);

count++;
//if (count > 100)
Expand All @@ -125,7 +125,7 @@ int main(int argc, char **argv)

clog << "Flush frames;\n";
while (true) {
VideoFrame2 frame = vdec.decodeVideo(Packet(), ec);
VideoFrame frame = vdec.decodeVideo(Packet(), ec);
if (ec) {
cerr << "Error: " << ec << ", " << ec.message() << endl;
return 1;
Expand Down
6 changes: 3 additions & 3 deletions example/api2-samples/api2-scale-video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main(int argc, char **argv)
FormatContext ictx;
ssize_t videoStream = -1;
CodecContext vdec;
Stream2 vst;
Stream vst;

int count = 0;

Expand Down Expand Up @@ -97,7 +97,7 @@ int main(int argc, char **argv)
octx.setFormat(ofrmt);

Codec ocodec = findEncodingCodec(ofrmt);
Stream2 ost = octx.addStream(ocodec);
Stream ost = octx.addStream(ocodec);
CodecContext encoder {ost};

// Settings
Expand Down Expand Up @@ -182,7 +182,7 @@ int main(int argc, char **argv)
clog << "inpFrame: pts=" << inpFrame.pts() << " / " << inpFrame.pts().seconds() << " / " << inpFrame.timeBase() << ", " << inpFrame.width() << "x" << inpFrame.height() << ", size=" << inpFrame.size() << ", ref=" << inpFrame.isReferenced() << ":" << inpFrame.refCount() << " / type: " << inpFrame.pictureType() << endl;

// SCALE
//VideoFrame2 outFrame {encoder.pixelFormat(), encoder.width(), encoder.height()};
//VideoFrame outFrame {encoder.pixelFormat(), encoder.width(), encoder.height()};
//rescaler.rescale(outFrame, inpFrame, ec);
auto outFrame = rescaler.rescale(inpFrame, ec);
if (ec) {
Expand Down
18 changes: 9 additions & 9 deletions src/audioresampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ SampleFormat AudioResampler::srcSampleFormat() const
return m_srcFormat;
}

bool AudioResampler::pop(AudioSamples2 &dst, bool getall, error_code &ec)
bool AudioResampler::pop(AudioSamples &dst, bool getall, error_code &ec)
{
clear_if(ec);

Expand Down Expand Up @@ -170,40 +170,40 @@ bool AudioResampler::pop(AudioSamples2 &dst, bool getall, error_code &ec)
return dst.samplesCount() ? true : false;
}

AudioSamples2 AudioResampler::pop(size_t samplesCount, error_code &ec)
AudioSamples AudioResampler::pop(size_t samplesCount, error_code &ec)
{
clear_if(ec);

if (!m_raw)
{
fflog(AV_LOG_ERROR, "SwrContext does not inited\n");
throws_if(ec, Errors::ResamplerNotInited);
return AudioSamples2(nullptr);
return AudioSamples(nullptr);
}

auto delay = swr_get_delay(m_raw, m_dstRate);

// Need more data
if ((size_t)delay < samplesCount && samplesCount)
{
return AudioSamples2(nullptr);
return AudioSamples(nullptr);
}

if (!samplesCount)
samplesCount = delay; // Request all samples

AudioSamples2 dst(dstSampleFormat(), samplesCount, dstChannelLayout(), dstSampleRate());
AudioSamples dst(dstSampleFormat(), samplesCount, dstChannelLayout(), dstSampleRate());
if (!dst.isValid())
{
throws_if(ec, Errors::CantAllocateFrame);
return AudioSamples2(nullptr);
return AudioSamples(nullptr);
}

auto sts = swr_convert_frame(m_raw, dst.raw(), nullptr);
if (sts < 0)
{
throws_if(ec, sts, ffmpeg_category());
return AudioSamples2(nullptr);
return AudioSamples(nullptr);
}

dst.setTimeBase(Rational(1, m_dstRate));
Expand All @@ -217,10 +217,10 @@ AudioSamples2 AudioResampler::pop(size_t samplesCount, error_code &ec)
dst.setPts(m_nextPts);
m_nextPts = dst.pts() + Timestamp(dst.samplesCount(), dst.timeBase());

return dst.samplesCount() ? std::move(dst) : AudioSamples2::null();
return dst.samplesCount() ? std::move(dst) : AudioSamples::null();
}

void AudioResampler::push(const AudioSamples2 &src, error_code &ec)
void AudioResampler::push(const AudioSamples &src, error_code &ec)
{
if (!m_raw)
{
Expand Down
6 changes: 3 additions & 3 deletions src/audioresampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AudioResampler : public FFWrapperPtr<SwrContext>, public noncopyable
* @param[in,out] ec this represents the error status on exit, if this is pre-initialized to
* av#throws the function will throw on error instead
*/
void push(const AudioSamples2 &src, std::error_code &ec = throws());
void push(const AudioSamples &src, std::error_code &ec = throws());

/**
* @brief Pop frame from the rescaler context.
Expand All @@ -71,7 +71,7 @@ class AudioResampler : public FFWrapperPtr<SwrContext>, public noncopyable
* av#throws the function will throw on error instead
* @return false if no samples avail, true otherwise. On error false.
*/
bool pop(AudioSamples2 &dst, bool getall, std::error_code &ec = throws());
bool pop(AudioSamples &dst, bool getall, std::error_code &ec = throws());

/**
* @brief Pop frame from the rescaler context.
Expand All @@ -86,7 +86,7 @@ class AudioResampler : public FFWrapperPtr<SwrContext>, public noncopyable
* av#throws the function will throw on error instead
* @return resampled samples or null-frame when no requested samples avail. On error null-frame.
*/
AudioSamples2 pop(size_t samplesCount, std::error_code &ec = throws());
AudioSamples pop(size_t samplesCount, std::error_code &ec = throws());

bool isValid() const;
operator bool() const { return isValid(); }
Expand Down
34 changes: 17 additions & 17 deletions src/codeccontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CodecContext::CodecContext()
m_raw = avcodec_alloc_context3(nullptr);
}

CodecContext::CodecContext(const Stream2 &st, const Codec &codec)
CodecContext::CodecContext(const Stream &st, const Codec &codec)
: m_stream(st)
{
m_raw = st.raw()->codec;
Expand Down Expand Up @@ -253,7 +253,7 @@ void CodecContext::setTimeBase(const Rational &value)
RAW_SET2(isValid(), time_base, value.getValue());
}

const Stream2 &CodecContext::stream() const
const Stream &CodecContext::stream() const
{
return m_stream;
}
Expand Down Expand Up @@ -626,34 +626,34 @@ bool CodecContext::isFlags2(int flags)
return false;
}

VideoFrame2 CodecContext::decodeVideo(const Packet &packet, error_code &ec, bool autoAllocateFrame)
VideoFrame CodecContext::decodeVideo(const Packet &packet, error_code &ec, bool autoAllocateFrame)
{
return decodeVideo(ec, packet, 0, nullptr, autoAllocateFrame);
}

VideoFrame2 CodecContext::decodeVideo(const Packet &packet, size_t offset, size_t &decodedBytes, error_code &ec, bool autoAllocateFrame)
VideoFrame CodecContext::decodeVideo(const Packet &packet, size_t offset, size_t &decodedBytes, error_code &ec, bool autoAllocateFrame)
{
return decodeVideo(ec, packet, offset, &decodedBytes, autoAllocateFrame);
}

Packet CodecContext::encodeVideo(error_code &ec)
{
return encodeVideo(VideoFrame2(nullptr), ec);
return encodeVideo(VideoFrame(nullptr), ec);
}

VideoFrame2 CodecContext::decodeVideo(error_code &ec, const Packet &packet, size_t offset, size_t *decodedBytes, bool autoAllocateFrame)
VideoFrame CodecContext::decodeVideo(error_code &ec, const Packet &packet, size_t offset, size_t *decodedBytes, bool autoAllocateFrame)
{
clear_if(ec);

VideoFrame2 outFrame;
VideoFrame outFrame;
if (!autoAllocateFrame)
{
outFrame = {pixelFormat(), width(), height(), 32};

if (!outFrame.isValid())
{
throws_if(ec, Errors::FrameInvalid);
return VideoFrame2();
return VideoFrame();
}
}

Expand All @@ -662,11 +662,11 @@ VideoFrame2 CodecContext::decodeVideo(error_code &ec, const Packet &packet, size

if (get<1>(st)) {
throws_if(ec, get<0>(st), *get<1>(st));
return VideoFrame2();
return VideoFrame();
}

if (!gotFrame)
return VideoFrame2();
return VideoFrame();

outFrame.setPictureType(AV_PICTURE_TYPE_I);

Expand All @@ -677,7 +677,7 @@ VideoFrame2 CodecContext::decodeVideo(error_code &ec, const Packet &packet, size
}


Packet CodecContext::encodeVideo(const VideoFrame2 &inFrame, error_code &ec)
Packet CodecContext::encodeVideo(const VideoFrame &inFrame, error_code &ec)
{
clear_if(ec);

Expand All @@ -703,23 +703,23 @@ Packet CodecContext::encodeVideo(const VideoFrame2 &inFrame, error_code &ec)
return packet;
}

AudioSamples2 CodecContext::decodeAudio(const Packet &inPacket, error_code &ec)
AudioSamples CodecContext::decodeAudio(const Packet &inPacket, error_code &ec)
{
return decodeAudio(inPacket, 0, ec);
}

AudioSamples2 CodecContext::decodeAudio(const Packet &inPacket, size_t offset, error_code &ec)
AudioSamples CodecContext::decodeAudio(const Packet &inPacket, size_t offset, error_code &ec)
{
clear_if(ec);

AudioSamples2 outSamples;
AudioSamples outSamples;

int gotFrame = 0;
auto st = decodeCommon(outSamples, inPacket, offset, gotFrame, avcodec_decode_audio4);
if (get<1>(st))
{
throws_if(ec, get<0>(st), *get<1>(st));
return AudioSamples2();
return AudioSamples();
}

if (!gotFrame)
Expand All @@ -737,10 +737,10 @@ AudioSamples2 CodecContext::decodeAudio(const Packet &inPacket, size_t offset, e

Packet CodecContext::encodeAudio(error_code &ec)
{
return encodeAudio(AudioSamples2(nullptr), ec);
return encodeAudio(AudioSamples(nullptr), ec);
}

Packet CodecContext::encodeAudio(const AudioSamples2 &inSamples, error_code &ec)
Packet CodecContext::encodeAudio(const AudioSamples &inSamples, error_code &ec)
{
clear_if(ec);

Expand Down
Loading

0 comments on commit deef359

Please sign in to comment.