support vn/an to disable video/audio, for radio streaming

pull/133/head
winlin 11 years ago
parent 747bbd988e
commit b7d40b5aba

@ -291,6 +291,25 @@ vhost audio.transcode.vhost.com {
}
}
}
# disable video, transcode/copy audio.
# for example, publish pure audio stream.
vhost vn.transcode.vhost.com {
transcode {
enabled on;
ffmpeg ./objs/ffmpeg/bin/ffmpeg;
engine vn {
enabled on;
vcodec vn;
acodec libaacplus;
abitrate 45;
asample_rate 44100;
achannels 2;
aparams {
}
output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];
}
}
}
# ffmpeg-copy(forward implements by ffmpeg).
# copy the video and audio to a new stream.
vhost copy.transcode.vhost.com {
@ -333,6 +352,7 @@ vhost all.transcode.vhost.com {
# video encoder name. can be:
# libx264: use h.264(libx264) video encoder.
# copy: donot encoder the video stream, copy it.
# vn: disable video output.
vcodec libx264;
# video bitrate, in kbps
vbitrate 1500;
@ -364,6 +384,7 @@ vhost all.transcode.vhost.com {
# audio encoder name. can be:
# libaacplus: use aac(libaacplus) audio encoder.
# copy: donot encoder the audio stream, copy it.
# an: disable audio output.
acodec libaacplus;
# audio bitrate, in kbps. [16, 72] for libaacplus.
abitrate 70;

@ -3,4 +3,19 @@
listen 1935;
vhost __defaultVhost__ {
transcode {
enabled on;
ffmpeg ./objs/ffmpeg/bin/ffmpeg;
engine vn {
enabled on;
vcodec vn;
acodec libaacplus;
abitrate 45;
asample_rate 44100;
achannels 2;
aparams {
}
output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];
}
}
}

@ -42,6 +42,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifdef SRS_FFMPEG
#define SRS_ENCODER_COPY "copy"
#define SRS_ENCODER_NO_VIDEO "vn"
#define SRS_ENCODER_NO_AUDIO "an"
#define SRS_ENCODER_VCODEC "libx264"
#define SRS_ENCODER_ACODEC "libaacplus"
@ -138,7 +140,13 @@ int SrsFFMPEG::initialize(SrsRequest* req, SrsConfDirective* engine)
}
_transcoded_url.push_back(output);
if (vcodec != SRS_ENCODER_COPY) {
if (vcodec == SRS_ENCODER_NO_VIDEO && acodec == SRS_ENCODER_NO_AUDIO) {
ret = ERROR_ENCODER_VCODEC;
srs_warn("video and audio disabled. ret=%d", ret);
return ret;
}
if (vcodec != SRS_ENCODER_COPY && vcodec != SRS_ENCODER_NO_VIDEO) {
if (vcodec != SRS_ENCODER_VCODEC) {
ret = ERROR_ENCODER_VCODEC;
srs_error("invalid vcodec, must be %s, actual %s, ret=%d",
@ -182,7 +190,7 @@ int SrsFFMPEG::initialize(SrsRequest* req, SrsConfDirective* engine)
}
}
if (acodec != SRS_ENCODER_COPY) {
if (acodec != SRS_ENCODER_COPY && acodec != SRS_ENCODER_NO_AUDIO) {
if (acodec != SRS_ENCODER_ACODEC) {
ret = ERROR_ENCODER_ACODEC;
srs_error("invalid acodec, must be %s, actual %s, ret=%d",
@ -254,11 +262,15 @@ int SrsFFMPEG::start()
}
// video specified.
params.push_back("-vcodec");
params.push_back(vcodec);
if (vcodec != SRS_ENCODER_NO_VIDEO) {
params.push_back("-vcodec");
params.push_back(vcodec);
} else {
params.push_back("-vn");
}
// the codec params is disabled when copy
if (vcodec != SRS_ENCODER_COPY) {
if (vcodec != SRS_ENCODER_COPY && vcodec != SRS_ENCODER_NO_VIDEO) {
params.push_back("-b:v");
snprintf(tmp, sizeof(tmp), "%d", vbitrate * 1000);
params.push_back(tmp);
@ -299,11 +311,15 @@ int SrsFFMPEG::start()
}
// audio specified.
params.push_back("-acodec");
params.push_back(acodec);
if (acodec != SRS_ENCODER_NO_AUDIO) {
params.push_back("-acodec");
params.push_back(acodec);
} else {
params.push_back("-an");
}
// the codec params is disabled when copy
if (acodec != SRS_ENCODER_COPY) {
if (acodec != SRS_ENCODER_COPY && acodec != SRS_ENCODER_NO_AUDIO) {
params.push_back("-b:a");
snprintf(tmp, sizeof(tmp), "%d", abitrate * 1000);
params.push_back(tmp);

File diff suppressed because it is too large Load Diff

@ -97,6 +97,78 @@ namespace srs
int random1_size;
};
// the digest key generate size.
#define OpensslHashSize 512
extern u_int8_t SrsGenuineFMSKey[];
extern u_int8_t SrsGenuineFPKey[];
int openssl_HMACsha256(const void* data, int data_size, const void* key, int key_size, void* digest);
int openssl_generate_key(char* _private_key, char* _public_key, int32_t size);
// calc the offset of key,
// the key->offset cannot be used as the offset of key.
int srs_key_block_get_offset(key_block* key);
// create new key block data.
// if created, user must free it by srs_key_block_free
void srs_key_block_init(key_block* key);
// parse key block from c1s1.
// if created, user must free it by srs_key_block_free
// @c1s1_key_bytes the key start bytes, maybe c1s1 or c1s1+764
int srs_key_block_parse(key_block* key, char* c1s1_key_bytes);
// free the block data create by
// srs_key_block_init or srs_key_block_parse
void srs_key_block_free(key_block* key);
// calc the offset of digest,
// the key->offset cannot be used as the offset of digest.
int srs_digest_block_get_offset(digest_block* digest);
// create new digest block data.
// if created, user must free it by srs_digest_block_free
void srs_digest_block_init(digest_block* digest);
// parse digest block from c1s1.
// if created, user must free it by srs_digest_block_free
// @c1s1_digest_bytes the digest start bytes, maybe c1s1 or c1s1+764
int srs_digest_block_parse(digest_block* digest, char* c1s1_digest_bytes);
// free the block data create by
// srs_digest_block_init or srs_digest_block_parse
void srs_digest_block_free(digest_block* digest);
/**
* copy whole c1s1 to bytes.
*/
void srs_schema0_copy_to(char* bytes, bool with_digest,
int32_t time, int32_t version, key_block* key, digest_block* digest);
void srs_schema1_copy_to(char* bytes, bool with_digest,
int32_t time, int32_t version, digest_block* digest, key_block* key);
/**
* c1s1 is splited by digest:
* c1s1-part1: n bytes (time, version, key and digest-part1).
* digest-data: 32bytes
* c1s1-part2: (1536-n-32)bytes (digest-part2)
* @return a new allocated bytes, user must free it.
*/
char* srs_bytes_join_schema0(int32_t time, int32_t version, key_block* key, digest_block* digest);
/**
* c1s1 is splited by digest:
* c1s1-part1: n bytes (time, version and digest-part1).
* digest-data: 32bytes
* c1s1-part2: (1536-n-32)bytes (digest-part2 and key)
* @return a new allocated bytes, user must free it.
*/
char* srs_bytes_join_schema1(int32_t time, int32_t version, digest_block* digest, key_block* key);
/**
* compare the memory in bytes.
*/
bool srs_bytes_equals(void* pa, void* pb, int size);
/**
* c1s1 schema0
* time: 4bytes
@ -236,35 +308,6 @@ namespace srs
*/
virtual int s2_validate(c1s1* c1, bool& is_valid);
};
/**
* compare the memory in bytes.
*/
bool srs_bytes_equals(void* pa, void* pb, int size);
/**
* c1s1 is splited by digest:
* c1s1-part1: n bytes (time, version, key and digest-part1).
* digest-data: 32bytes
* c1s1-part2: (1536-n-32)bytes (digest-part2)
* @return a new allocated bytes, user must free it.
*/
char* srs_bytes_join_schema0(int32_t time, int32_t version, key_block* key, digest_block* digest);
/**
* c1s1 is splited by digest:
* c1s1-part1: n bytes (time, version and digest-part1).
* digest-data: 32bytes
* c1s1-part2: (1536-n-32)bytes (digest-part2 and key)
* @return a new allocated bytes, user must free it.
*/
char* srs_bytes_join_schema1(int32_t time, int32_t version, digest_block* digest, key_block* key);
// the digest key generate size.
#define OpensslHashSize 512
extern u_int8_t SrsGenuineFMSKey[];
extern u_int8_t SrsGenuineFPKey[];
int openssl_HMACsha256(const void* data, int data_size, const void* key, int key_size, void* digest);
}
#endif

@ -172,7 +172,7 @@ VOID TEST(HandshakeTest, VerifyFPC0C1)
0xb1, 0xb5, 0xbc, 0xa6, 0xd6, 0xd6, 0x1d, 0xce, 0x93, 0x78, 0xb3, 0xec, 0xa8, 0x64, 0x19, 0x13
};
EXPECT_TRUE(srs_bytes_equals(c1.block1.digest.digest, digest, 32));
}
}
VOID TEST(HandshakeTest, SimpleHandshake)
{
@ -260,3 +260,8 @@ VOID TEST(HandshakeTest, ComplexHandshake)
ASSERT_TRUE(is_valid);
}
}
VOID TEST(HandshakeTest, BytesEqual)
{
//srs_bytes_equals
}

Loading…
Cancel
Save