Skip to content

Commit df1c662

Browse files
committed
Merge pull request #186 from cchampet/dev_audioReaderChannelIndex
AudioReader: can specify the channel index
2 parents 0c9a2ba + 54d4cbe commit df1c662

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1127
-883
lines changed

app/avPlay/Window.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
21
#include "Window.hpp"
32

3+
#include <AvTranscoder/properties/print.hpp>
4+
45
#ifdef __APPLE__
56
#include <OpenGL/gl.h>
67
#include <GLUT/glut.h>
@@ -103,8 +104,8 @@ void loadNewTexture(const char* data, GLint internalFormat, size_t width, size_t
103104
Window::Window(avtranscoder::VideoReader& reader)
104105
{
105106
_reader = &reader;
106-
_width = _reader->getWidth();
107-
_height = _reader->getHeight();
107+
_width = _reader->getOutputWidth();
108+
_height = _reader->getOutputHeight();
108109

109110
char* argv[2] = {(char*)"", NULL};
110111
int argc = 1;
@@ -439,7 +440,9 @@ void Window::displayInformations()
439440
std::cout << textureType << " " << _width << "x" << _height << std::endl;
440441

441442
// stream info
442-
_reader->printInfo();
443+
const avtranscoder::VideoProperties* properties = _reader->getSourceVideoProperties();
444+
if(properties != NULL)
445+
std::cout << *properties << std::endl;
443446
}
444447

445448
void Window::move(float x, float y)
@@ -547,15 +550,17 @@ void Window::showAlphaChannelTexture()
547550

548551
void Window::displayNextFrame()
549552
{
550-
const char* buffer = (const char*)_reader->readNextFrame()->getData();
551-
loadNewTexture(buffer, _reader->getComponents(), _reader->getWidth(), _reader->getHeight(), GL_RGB, GL_UNSIGNED_BYTE);
553+
const char* buffer = (const char*)_reader->readNextFrame()->getData()[0];
554+
loadNewTexture(buffer, _reader->getOutputNbComponents(), _reader->getOutputWidth(), _reader->getOutputHeight(), GL_RGB,
555+
GL_UNSIGNED_BYTE);
552556
display();
553557
}
554558

555559
void Window::displayPrevFrame()
556560
{
557-
const char* buffer = (const char*)_reader->readPrevFrame()->getData();
558-
loadNewTexture(buffer, _reader->getComponents(), _reader->getWidth(), _reader->getHeight(), GL_RGB, GL_UNSIGNED_BYTE);
561+
const char* buffer = (const char*)_reader->readPrevFrame()->getData()[0];
562+
loadNewTexture(buffer, _reader->getOutputNbComponents(), _reader->getOutputWidth(), _reader->getOutputHeight(), GL_RGB,
563+
GL_UNSIGNED_BYTE);
559564
display();
560565
}
561566

@@ -566,8 +571,9 @@ void Window::displayFirstFrame()
566571

567572
void Window::displayAtFrame(const size_t frame)
568573
{
569-
const char* buffer = (const char*)_reader->readFrameAt(frame)->getData();
570-
loadNewTexture(buffer, _reader->getComponents(), _reader->getWidth(), _reader->getHeight(), GL_RGB, GL_UNSIGNED_BYTE);
574+
const char* buffer = (const char*)_reader->readFrameAt(frame)->getData()[0];
575+
loadNewTexture(buffer, _reader->getOutputNbComponents(), _reader->getOutputWidth(), _reader->getOutputHeight(), GL_RGB,
576+
GL_UNSIGNED_BYTE);
571577
display();
572578
}
573579

app/avPlay/main.cpp

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,90 @@
33

44
#include "Window.hpp"
55

6+
#include <cstdlib>
7+
68
int main(int argc, char** argv)
79
{
8-
avtranscoder::preloadCodecsAndFormats();
10+
std::string filename;
11+
size_t streamIndex = 0;
12+
size_t width = 0;
13+
size_t height = 0;
14+
15+
std::string help;
16+
help += "Usage\n";
17+
help += "\tavplay filename [streamIndex] [--width width] [--height height] [--help]\n";
18+
help += "Command line options\n";
19+
help += "\tstreamIndex: specify the index of the stream to read (by default 0)\n";
20+
help += "\t--width: specify the output width (by default the same as input)\n";
21+
help += "\t--height: specify the output height (by default the same as input)\n";
22+
help += "\t--help: display this help\n";
923

24+
// List command line arguments
25+
std::vector<std::string> arguments;
26+
for(int argument = 1; argument < argc; ++argument)
27+
{
28+
arguments.push_back(argv[argument]);
29+
}
30+
for(size_t argument = 0; argument < arguments.size(); ++argument)
31+
{
32+
if(arguments.at(argument) == "--help")
33+
{
34+
std::cout << help << std::endl;
35+
return 0;
36+
}
37+
else if(arguments.at(argument) == "--width")
38+
{
39+
try
40+
{
41+
width = atoi(arguments.at(++argument).c_str());
42+
}
43+
catch(...)
44+
{
45+
std::cout << help << std::endl;
46+
return 0;
47+
}
48+
}
49+
else if(arguments.at(argument) == "--height")
50+
{
51+
try
52+
{
53+
height = atoi(arguments.at(++argument).c_str());
54+
}
55+
catch(...)
56+
{
57+
std::cout << help << std::endl;
58+
return 0;
59+
}
60+
}
61+
// positional arguments
62+
if(argument == 0)
63+
{
64+
filename = arguments.at(argument);
65+
}
66+
else if(argument == 1)
67+
{
68+
streamIndex = atoi(arguments.at(argument).c_str());
69+
}
70+
}
71+
72+
// Check required arguments
1073
if(argc < 2)
1174
{
1275
std::cout << "avplay can play the given video media file." << std::endl;
13-
std::cout << "Provide the filename and the streamIndex (0 by default)" << std::endl;
76+
std::cout << "Use option --help to display help" << std::endl;
1477
return (-1);
1578
}
1679

17-
const std::string filename(argv[1]);
18-
const size_t streamIndex = argc > 2 ? atoi(argv[2]) : 0;
80+
// Setup avtranscoder
81+
avtranscoder::preloadCodecsAndFormats();
82+
avtranscoder::Logger::setLogLevel(AV_LOG_QUIET);
1983

2084
avtranscoder::VideoReader reader(filename, streamIndex);
85+
if(width == 0)
86+
width = reader.getOutputWidth();
87+
if(height == 0)
88+
height = reader.getOutputHeight();
89+
reader.updateOutput(width, height, "rgb24");
2190
Window window(reader);
2291
window.launch();
2392
}

src/AvTranscoder/Library.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Libraries getLibraries()
7777
{
7878
Libraries libs;
7979

80-
libs.push_back(Library("avtranscoder", "GPL or LGPL version 3", AVTRANSCODER_VERSION_MAJOR, AVTRANSCODER_VERSION_MINOR,
80+
libs.push_back(Library("avtranscoder", "GPL v2 or LGPL v2.1", AVTRANSCODER_VERSION_MAJOR, AVTRANSCODER_VERSION_MINOR,
8181
AVTRANSCODER_VERSION_MICRO));
8282
libs.push_back(
8383
Library("avutil", avutil_license(), LIBAVUTIL_VERSION_MAJOR, LIBAVUTIL_VERSION_MINOR, LIBAVUTIL_VERSION_MICRO));

src/AvTranscoder/avTranscoder.i

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
%include "AvTranscoder/progress/progress.i"
2525
%include "AvTranscoder/properties/properties.i"
26-
%include "AvTranscoder/frame/frame.i"
26+
%include "AvTranscoder/data/data.i"
2727
%include "AvTranscoder/profile/profile.i"
2828

2929
%include <AvTranscoder/Library.hpp>

src/AvTranscoder/codec/AudioCodec.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ AudioCodec::AudioCodec(const ECodecType type, AVCodecContext& avCodecContext)
2424
AudioFrameDesc AudioCodec::getAudioFrameDesc() const
2525
{
2626
assert(_avCodecContext != NULL);
27-
AudioFrameDesc audioFrameDesc(_avCodecContext->sample_rate, _avCodecContext->channels, _avCodecContext->sample_fmt);
28-
return audioFrameDesc;
27+
return AudioFrameDesc(_avCodecContext->sample_rate, _avCodecContext->channels, _avCodecContext->sample_fmt);
2928
}
3029

3130
void AudioCodec::setAudioParameters(const AudioFrameDesc& audioFrameDesc)
3231
{
33-
_avCodecContext->sample_rate = audioFrameDesc.getSampleRate();
34-
_avCodecContext->channels = audioFrameDesc.getChannels();
35-
_avCodecContext->sample_fmt = audioFrameDesc.getSampleFormat();
32+
_avCodecContext->sample_rate = audioFrameDesc._sampleRate;
33+
_avCodecContext->channels = audioFrameDesc._nbChannels;
34+
_avCodecContext->sample_fmt = audioFrameDesc._sampleFormat;
3635
}
3736
}

src/AvTranscoder/codec/AudioCodec.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define _AV_TRANSCODER_CODEC_AUDIO_CODEC_HPP_
33

44
#include "ICodec.hpp"
5-
#include <AvTranscoder/frame/AudioFrame.hpp>
5+
#include <AvTranscoder/data/decoded/AudioFrame.hpp>
66

77
namespace avtranscoder
88
{

src/AvTranscoder/codec/VideoCodec.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ VideoFrameDesc VideoCodec::getVideoFrameDesc() const
2727
VideoFrameDesc videoFrameDesc(_avCodecContext->width, _avCodecContext->height, _avCodecContext->pix_fmt);
2828
double fps = 1.0 * _avCodecContext->time_base.den / (_avCodecContext->time_base.num * _avCodecContext->ticks_per_frame);
2929
if(!std::isinf(fps))
30-
videoFrameDesc.setFps(fps);
30+
videoFrameDesc._fps = fps;
3131
return videoFrameDesc;
3232
}
3333

3434
void VideoCodec::setImageParameters(const VideoFrameDesc& videoFrameDesc)
3535
{
36-
_avCodecContext->width = videoFrameDesc.getWidth();
37-
_avCodecContext->height = videoFrameDesc.getHeight();
38-
_avCodecContext->pix_fmt = videoFrameDesc.getPixelFormat();
36+
_avCodecContext->width = videoFrameDesc._width;
37+
_avCodecContext->height = videoFrameDesc._height;
38+
_avCodecContext->pix_fmt = videoFrameDesc._pixelFormat;
3939
_avCodecContext->time_base.num = 1;
40-
_avCodecContext->time_base.den = videoFrameDesc.getFps();
40+
_avCodecContext->time_base.den = videoFrameDesc._fps;
4141
_avCodecContext->ticks_per_frame = 1;
4242
}
4343
}

src/AvTranscoder/codec/VideoCodec.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define _AV_TRANSCODER_CODEC_VIDEO_CODEC_HPP_
33

44
#include "ICodec.hpp"
5-
#include <AvTranscoder/frame/VideoFrame.hpp>
5+
#include <AvTranscoder/data/decoded/VideoFrame.hpp>
66

77
namespace avtranscoder
88
{

src/AvTranscoder/frame/Frame.cpp renamed to src/AvTranscoder/data/coded/CodedData.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,93 @@
1-
#include "Frame.hpp"
1+
#include "CodedData.hpp"
22

33
#include <cstring>
44

55
namespace avtranscoder
66
{
77

8-
Frame::Frame()
8+
CodedData::CodedData()
99
: _avStream(NULL)
1010
{
1111
initAVPacket();
1212
}
1313

14-
Frame::Frame(const size_t dataSize)
14+
CodedData::CodedData(const size_t dataSize)
1515
: _avStream(NULL)
1616
{
1717
av_new_packet(&_packet, dataSize);
1818
}
1919

20-
Frame::Frame(const AVPacket& avPacket)
20+
CodedData::CodedData(const AVPacket& avPacket)
2121
: _avStream(NULL)
2222
{
2323
copyAVPacket(avPacket);
2424
}
2525

26-
Frame::Frame(const Frame& other)
26+
CodedData::CodedData(const CodedData& other)
2727
{
2828
copyAVPacket(other.getAVPacket());
2929
_avStream = other.getAVStream();
3030
}
3131

32-
Frame& Frame::operator=(const Frame& other)
32+
CodedData& CodedData::operator=(const CodedData& other)
3333
{
3434
copyAVPacket(other.getAVPacket());
3535
_avStream = other.getAVStream();
3636
return *this;
3737
}
3838

39-
Frame::~Frame()
39+
CodedData::~CodedData()
4040
{
4141
av_free_packet(&_packet);
4242
}
4343

44-
void Frame::resize(const size_t newSize)
44+
void CodedData::resize(const size_t newSize)
4545
{
4646
if((int)newSize < _packet.size)
4747
av_shrink_packet(&_packet, newSize);
4848
else if((int)newSize > _packet.size)
4949
av_grow_packet(&_packet, newSize - _packet.size);
5050
}
5151

52-
void Frame::refData(unsigned char* buffer, const size_t size)
52+
void CodedData::refData(unsigned char* buffer, const size_t size)
5353
{
5454
_packet.data = buffer;
5555
_packet.size = size;
5656
}
5757

58-
void Frame::copyData(unsigned char* buffer, const size_t size)
58+
void CodedData::copyData(unsigned char* buffer, const size_t size)
5959
{
6060
resize(size);
6161
if(size != 0)
6262
memcpy(_packet.data, buffer, _packet.size);
6363
}
6464

65-
void Frame::refData(Frame& frame)
65+
void CodedData::refData(CodedData& frame)
6666
{
6767
_packet.data = frame.getData();
6868
_packet.size = frame.getSize();
6969
}
7070

71-
void Frame::clear()
71+
void CodedData::clear()
7272
{
7373
av_free_packet(&_packet);
7474
initAVPacket();
7575
}
7676

77-
void Frame::assign(const size_t size, const int value)
77+
void CodedData::assign(const size_t size, const int value)
7878
{
7979
resize(size);
8080
memset(_packet.data, value, size);
8181
}
8282

83-
void Frame::initAVPacket()
83+
void CodedData::initAVPacket()
8484
{
8585
av_init_packet(&_packet);
8686
_packet.data = NULL;
8787
_packet.size = 0;
8888
}
8989

90-
void Frame::copyAVPacket(const AVPacket& avPacket)
90+
void CodedData::copyAVPacket(const AVPacket& avPacket)
9191
{
9292
#if AVTRANSCODER_FFMPEG_DEPENDENCY && LIBAVCODEC_VERSION_INT > AV_VERSION_INT(54, 56, 0)
9393
// Need const_cast<AVCodec*> for libav versions from 54.56. to 55.56.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy