Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc20fc7c

Browse files
Merge pull request#28 from cchampet/dev_Dummy
Dummy stream: new way to add
2 parents265f968 +717aa26 commitc20fc7c

19 files changed

+407
-489
lines changed
Lines changed: 19 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -1,200 +1,38 @@
11
#include"AudioDesc.hpp"
2-
#include"AudioFrame.hpp"
32

4-
extern"C" {
5-
#ifndef __STDC_CONSTANT_MACROS
6-
#define__STDC_CONSTANT_MACROS
7-
#endif
8-
#include<libavcodec/avcodec.h>
9-
#include<libavformat/avformat.h>
10-
#include<libavutil/avutil.h>
11-
#include<libavutil/pixdesc.h>
12-
#include<libavutil/imgutils.h>
13-
#include<libavutil/mathematics.h>
14-
#include<libavutil/opt.h>
15-
#include<libavutil/error.h>
16-
}
17-
#include<iostream>
18-
#include<stdexcept>
19-
#include<sstream>
203
#include<cassert>
214

225
namespaceavtranscoder
236
{
247

258
AudioDesc::AudioDesc(const std::string& codecName )
26-
: m_codec(NULL )
27-
, m_codecContext(NULL )
9+
: EssenceDesc( codecName )
2810
{
29-
if( codecName.size() )
30-
setAudioCodec( codecName );
3111
}
3212

3313
AudioDesc::AudioDesc(const AVCodecID codecId )
34-
: m_codec(NULL )
35-
, m_codecContext(NULL )
14+
: EssenceDesc( codecId )
3615
{
37-
setAudioCodec( codecId );
3816
}
3917

40-
voidAudioDesc::setAudioCodec(const std::string& codecName )
18+
AudioDesc::AudioDesc(const EssenceDesc& essenceDesc )
19+
: EssenceDesc( essenceDesc.getCodecId() )
4120
{
42-
avcodec_register_all();// Warning: should be called only once
43-
m_codec =avcodec_find_encoder_by_name( codecName.c_str() );
44-
initCodecContext();
21+
m_codec = essenceDesc.getCodec();
22+
m_codecContext = essenceDesc.getCodecContext();
4523
}
4624

47-
voidAudioDesc::setAudioCodec(const AVCodecID codecId )
48-
{
49-
avcodec_register_all();// Warning: should be called only once
50-
m_codec =avcodec_find_encoder( codecId );
51-
initCodecContext();
52-
}
53-
54-
voidAudioDesc::setAudioParameters(constsize_t sampleRate,constsize_t channels,const AVSampleFormat sampleFormat )
55-
{
56-
m_codecContext->sample_rate = sampleRate;
57-
m_codecContext->channels = channels;
58-
m_codecContext->sample_fmt = sampleFormat;
59-
}
60-
61-
voidAudioDesc::initCodecContext( )
62-
{
63-
if( m_codec ==NULL )
64-
{
65-
throwstd::runtime_error("unknown audio codec" );
66-
}
67-
68-
if( ( m_codecContext =avcodec_alloc_context3( m_codec ) ) ==NULL )
69-
{
70-
throwstd::runtime_error("unable to create context for audio context" );
71-
}
72-
73-
// Set default codec parameters
74-
if(avcodec_get_context_defaults3( m_codecContext, m_codec ) !=0 )
75-
{
76-
throwstd::runtime_error("unable to find audio codec default values" );
77-
}
78-
}
79-
80-
voidAudioDesc::set(const std::string& key,const std::string& flag,constbool enable )
25+
AudioFrameDescAudioDesc::getFrameDesc()const
8126
{
82-
int error =0;
83-
int64_t optVal;
27+
assert( m_codecContext !=NULL );
28+
AudioFrameDesc audioFrameDesc;
8429

85-
const AVOption* flagOpt =av_opt_find( m_codecContext, flag.c_str(), key.c_str(),0,0 );
86-
87-
if( ! flagOpt )
88-
{
89-
std::cout << flag << std::endl <<" :" << flagOpt->default_val.i64 << std::endl;
90-
throwstd::runtime_error("unknown flag" + flag );
91-
}
92-
93-
error =av_opt_get_int( m_codecContext, key.c_str(), AV_OPT_SEARCH_CHILDREN, &optVal );
94-
if( error !=0 )
95-
{
96-
std::stringerr("", AV_ERROR_MAX_STRING_SIZE );
97-
//av_make_error_string( const_cast<char*>(err.c_str()), err.size(), error );
98-
av_strerror( error,const_cast<char*>(err.c_str()), err.size() );
99-
throwstd::runtime_error("unknown key" + key +":" + err );
100-
}
101-
102-
if( enable )
103-
optVal = optVal | flagOpt->default_val.i64;
104-
else
105-
optVal = optVal &~ flagOpt->default_val.i64;
30+
audioFrameDesc.setChannels( m_codecContext->channels );
31+
audioFrameDesc.setSampleRate( m_codecContext->sample_rate );
32+
audioFrameDesc.setSampleFormat( m_codecContext->sample_fmt );
33+
// audioFrameDesc.setFps( 25 );
10634

107-
error =av_opt_set_int( m_codecContext, key.c_str(), optVal, AV_OPT_SEARCH_CHILDREN );
108-
if( error !=0 )
109-
{
110-
std::stringerr("", AV_ERROR_MAX_STRING_SIZE );
111-
//av_make_error_string( const_cast<char*>(err.c_str()), err.size(), error );
112-
av_strerror( error,const_cast<char*>(err.c_str()), err.size() );
113-
throwstd::runtime_error("setting" + key +" parameter to" + flag +":" + err );
114-
}
115-
}
116-
117-
voidAudioDesc::set(const std::string& key,constbool value )
118-
{
119-
int error =av_opt_set_int( m_codecContext, key.c_str(), value, AV_OPT_SEARCH_CHILDREN );
120-
if( error !=0 )
121-
{
122-
std::stringerr("", AV_ERROR_MAX_STRING_SIZE );
123-
//av_make_error_string( const_cast<char*>(err.c_str()), err.size(), error );
124-
av_strerror( error,const_cast<char*>(err.c_str()), err.size() );
125-
throwstd::runtime_error("setting" + key +" parameter to" + ( value ?"true" :"false" ) +":" + err );
126-
}
127-
}
128-
129-
voidAudioDesc::set(const std::string& key,constint value )
130-
{
131-
//const AVOption* flagOpt = av_opt_find( m_codecContext, key.c_str(), NULL, 0, AV_OPT_SEARCH_CHILDREN );
132-
133-
int error =av_opt_set_int( m_codecContext, key.c_str(), value, AV_OPT_SEARCH_CHILDREN );
134-
if( error !=0 )
135-
{
136-
std::ostringstream os;
137-
os << value;
138-
std::stringerr("", AV_ERROR_MAX_STRING_SIZE );
139-
//av_make_error_string( const_cast<char*>(err.c_str()), err.size(), error );
140-
av_strerror( error,const_cast<char*>(err.c_str()), err.size() );
141-
throwstd::runtime_error("setting" + key +" parameter to" + os.str() +":" + err );
142-
}
143-
}
144-
145-
voidAudioDesc::set(const std::string& key,constint num,constint den )
146-
{
147-
AVRational ratio;
148-
ratio.num = num;
149-
ratio.den = den;
150-
int error =av_opt_set_q( m_codecContext, key.c_str(), ratio, AV_OPT_SEARCH_CHILDREN );
151-
if( error !=0 )
152-
{
153-
std::ostringstream os;
154-
os << num <<"/" << den;
155-
std::stringerr("", AV_ERROR_MAX_STRING_SIZE );
156-
//av_make_error_string( const_cast<char*>(err.c_str()), err.size(), error );
157-
av_strerror( error,const_cast<char*>(err.c_str()), err.size() );
158-
throwstd::runtime_error("setting" + key +" parameter to" + os.str() +":" + err );
159-
}
160-
}
161-
162-
voidAudioDesc::set(const std::string& key,constdouble value )
163-
{
164-
int error =av_opt_set_double( m_codecContext, key.c_str(), value, AV_OPT_SEARCH_CHILDREN );
165-
if( error !=0 )
166-
{
167-
std::ostringstream os;
168-
os << value;
169-
std::stringerr("", AV_ERROR_MAX_STRING_SIZE );
170-
//av_make_error_string( const_cast<char*>(err.c_str()), err.size(), error );
171-
av_strerror( error,const_cast<char*>(err.c_str()), err.size() );
172-
throwstd::runtime_error("setting" + key +" parameter to" + os.str() +":" + err );
173-
}
174-
}
175-
176-
voidAudioDesc::set(const std::string& key,const std::string& value )
177-
{
178-
int error =av_opt_set( m_codecContext, key.c_str(), value.c_str(), AV_OPT_SEARCH_CHILDREN );
179-
if( error !=0 )
180-
{
181-
std::stringerr("", AV_ERROR_MAX_STRING_SIZE );
182-
//av_make_error_string( const_cast<char*>(err.c_str()), err.size(), error );
183-
av_strerror( error,const_cast<char*>(err.c_str()), err.size() );
184-
throwstd::runtime_error("setting" + key +" parameter to" + value +":" + err );
185-
}
186-
}
187-
188-
std::stringAudioDesc::getAudioCodec()const
189-
{
190-
assert( m_codecContext !=NULL );
191-
returnavcodec_descriptor_get( m_codecContext->codec_id )->name;
192-
}
193-
194-
AVCodecIDAudioDesc::getAudioCodecId()const
195-
{
196-
assert( m_codecContext !=NULL );
197-
return m_codecContext->codec_id;
35+
return audioFrameDesc;
19836
}
19937

20038
constsize_tAudioDesc::getSampleRate()const
@@ -215,18 +53,12 @@ const AVSampleFormat AudioDesc::getSampleFormat() const
21553
return m_codecContext->sample_fmt;
21654
}
21755

218-
AudioFrameDescAudioDesc::getFrameDesc()const
56+
57+
voidAudioDesc::setAudioParameters(constsize_t sampleRate,constsize_t channels,const AVSampleFormat sampleFormat )
21958
{
220-
assert( m_codecContext !=NULL );
221-
AudioFrameDesc audioFrameDesc;
222-
223-
audioFrameDesc.setChannels( m_codecContext->channels );
224-
audioFrameDesc.setSampleRate( m_codecContext->sample_rate );
225-
audioFrameDesc.setSampleFormat( m_codecContext->sample_fmt );
226-
// audioFrameDesc.setFps( 25 );
227-
228-
return audioFrameDesc;
59+
m_codecContext->sample_rate = sampleRate;
60+
m_codecContext->channels = channels;
61+
m_codecContext->sample_fmt = sampleFormat;
22962
}
23063

231-
23264
}

‎src/AvTranscoder/DatasStructures/AudioDesc.hpp

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef _AV_TRANSCODER_DATA_AUDIO_DESC_HPP_
22
#define_AV_TRANSCODER_DATA_AUDIO_DESC_HPP_
33

4-
#include"Image.hpp"
54
#include<string>
65

76
extern"C" {
@@ -15,50 +14,26 @@ extern "C" {
1514
#include<libavcodec/avcodec.h>
1615
}
1716

17+
#include<AvTranscoder/common.hpp>
18+
#include<AvTranscoder/DatasStructures/EssenceDesc.hpp>
1819
#include<AvTranscoder/DatasStructures/AudioFrame.hpp>
1920

2021
namespaceavtranscoder
2122
{
2223

23-
classAvExport AudioDesc
24+
classAvExport AudioDesc : public EssenceDesc
2425
{
2526
public:
2627
AudioDesc(const std::string& codecName ="" );
2728
AudioDesc(const AVCodecID codecId );
28-
29-
voidsetAudioCodec(const std::string& codecName );
30-
voidsetAudioCodec(const AVCodecID codecId );
31-
32-
voidsetAudioParameters(constsize_t sampleRate,constsize_t channels,const AVSampleFormat sampleFormat );
33-
34-
voidset(const std::string& key,const std::string& flag,constbool enable );
35-
voidset(const std::string& key,constbool value );
36-
voidset(const std::string& key,constint value );
37-
voidset(const std::string& key,constint num,constint den );
38-
voidset(const std::string& key,constdouble value );
39-
voidset(const std::string& key,const std::string& value );
29+
AudioDesc(const EssenceDesc& essenceDesc );
4030

41-
std::stringgetAudioCodec()const;
42-
AVCodecIDgetAudioCodecId()const;
43-
31+
AudioFrameDescgetFrameDesc()const;
4432
constsize_tgetSampleRate()const;
4533
constsize_tgetChannels()const;
4634
const AVSampleFormatgetSampleFormat()const;
47-
48-
#ifndef SWIG
49-
AVCodec*getCodec()const {return m_codec; }
50-
AVCodecContext*getCodecContext()const {return m_codecContext; }
51-
#endif
52-
53-
AudioFrameDescgetFrameDesc()const;
5435

55-
private:
56-
voidinitCodecContext( );
57-
58-
voidcheckError(int error );
59-
60-
AVCodec* m_codec;
61-
AVCodecContext* m_codecContext;
36+
voidsetAudioParameters(constsize_t sampleRate,constsize_t channels,const AVSampleFormat sampleFormat );
6237
};
6338

6439
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp