Improved RTSP output, added support for RTSP input
This commit is contained in:
parent
5c8ebdc5ec
commit
3465f2b587
5 changed files with 866 additions and 288 deletions
56
lib/adts.h
56
lib/adts.h
|
@ -1,4 +1,5 @@
|
|||
#include <string>
|
||||
#include "bitstream.h"
|
||||
|
||||
namespace aac {
|
||||
class adts {
|
||||
|
@ -26,4 +27,59 @@ namespace aac {
|
|||
char * data;
|
||||
unsigned long len;
|
||||
};
|
||||
|
||||
class AudSpecConf{
|
||||
public:
|
||||
static inline uint32_t rate(const std::string & conf){
|
||||
Utils::bitstream bs;
|
||||
bs.append(conf.data(), conf.size());
|
||||
if (bs.get(5) == 31){bs.skip(6);}//skip object type
|
||||
switch (bs.get(4)){//frequency index
|
||||
case 0: return 96000;
|
||||
case 1: return 88200;
|
||||
case 2: return 64000;
|
||||
case 3: return 48000;
|
||||
case 4: return 44100;
|
||||
case 5: return 32000;
|
||||
case 6: return 24000;
|
||||
case 7: return 22050;
|
||||
case 8: return 16000;
|
||||
case 9: return 12000;
|
||||
case 10: return 11025;
|
||||
case 11: return 8000;
|
||||
case 12: return 7350;
|
||||
case 15: return bs.get(24);
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
static inline uint16_t channels(const std::string & conf){
|
||||
Utils::bitstream bs;
|
||||
bs.append(conf.data(), conf.size());
|
||||
if (bs.get(5) == 31){bs.skip(6);}//skip object type
|
||||
if (bs.get(4) == 15){bs.skip(24);}//frequency index
|
||||
return bs.get(4);//channel configuration
|
||||
}
|
||||
static inline uint8_t objtype(const std::string & conf){
|
||||
Utils::bitstream bs;
|
||||
bs.append(conf.data(), conf.size());
|
||||
uint8_t ot = bs.get(5);
|
||||
if (ot == 31){return bs.get(6)+32;}
|
||||
return ot;
|
||||
}
|
||||
static inline uint16_t samples(const std::string & conf){
|
||||
Utils::bitstream bs;
|
||||
bs.append(conf.data(), conf.size());
|
||||
if (bs.get(5) == 31){bs.skip(6);}//skip object type
|
||||
if (bs.get(4) == 15){bs.skip(24);}//frequency index
|
||||
bs.skip(4);//channel configuration
|
||||
if (bs.get(1)){
|
||||
return 960;
|
||||
}else{
|
||||
return 1024;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
35
lib/rtp.cpp
35
lib/rtp.cpp
|
@ -6,12 +6,20 @@
|
|||
|
||||
namespace RTP {
|
||||
double Packet::startRTCP = 0;
|
||||
unsigned int MAX_SEND = 4*1024;
|
||||
unsigned int MAX_SEND = 1500-28;
|
||||
|
||||
unsigned int Packet::getHsize() const {
|
||||
return 12 + 4 * getContribCount();
|
||||
}
|
||||
|
||||
unsigned int Packet::getPayloadSize() const {
|
||||
return datalen - getHsize();
|
||||
}
|
||||
|
||||
char * Packet::getPayload() const {
|
||||
return data + getHsize();
|
||||
}
|
||||
|
||||
unsigned int Packet::getVersion() const {
|
||||
return (data[0] >> 6) & 0x3;
|
||||
}
|
||||
|
@ -70,17 +78,17 @@ namespace RTP {
|
|||
|
||||
void Packet::sendH264(void * socket, void callBack(void *, char *, unsigned int, unsigned int), const char * payload, unsigned int payloadlen, unsigned int channel) {
|
||||
/// \todo This function probably belongs in DMS somewhere.
|
||||
if (payloadlen <= MAX_SEND) {
|
||||
if (payloadlen+getHsize() <= MAX_SEND) {
|
||||
data[1] |= 0x80;//setting the RTP marker bit to 1
|
||||
memcpy(data + getHsize(), payload, payloadlen);
|
||||
callBack(socket, data, getHsize() + payloadlen, channel);
|
||||
sentPackets++;
|
||||
sentBytes += payloadlen;
|
||||
sentBytes += payloadlen+getHsize();
|
||||
increaseSequence();
|
||||
} else {
|
||||
data[1] &= 0x7F;//setting the RTP marker bit to 0
|
||||
unsigned int sent = 0;
|
||||
unsigned int sending = MAX_SEND;//packages are of size MAX_SEND, except for the final one
|
||||
unsigned int sending = MAX_SEND-getHsize()-2;//packages are of size MAX_SEND, except for the final one
|
||||
char initByte = (payload[0] & 0xE0) | 0x1C;
|
||||
char serByte = payload[0] & 0x1F; //ser is now 000
|
||||
data[getHsize()] = initByte;
|
||||
|
@ -90,17 +98,17 @@ namespace RTP {
|
|||
} else {
|
||||
serByte &= 0x7F;//set first bit to 0
|
||||
}
|
||||
if (sent + MAX_SEND >= payloadlen) {
|
||||
if (sent + sending >= payloadlen) {
|
||||
//last package
|
||||
serByte |= 0x40;
|
||||
sending = payloadlen - sent;
|
||||
data[1] |= 0x80;//setting the RTP marker bit to 1
|
||||
}
|
||||
data[getHsize() + 1] = serByte;
|
||||
memcpy(data + getHsize() + 2, payload + 1 + sent, sending); //+1 because
|
||||
memcpy(data + getHsize() + 2, payload + 1 + sent, sending);
|
||||
callBack(socket, data, getHsize() + 2 + sending, channel);
|
||||
sentPackets++;
|
||||
sentBytes += sending;
|
||||
sentBytes += sending+getHsize()+2;
|
||||
sent += sending;
|
||||
increaseSequence();
|
||||
}
|
||||
|
@ -128,19 +136,6 @@ namespace RTP {
|
|||
increaseSequence();
|
||||
}
|
||||
|
||||
/// Stores a long long (64 bits) value of val in network order to the pointer p.
|
||||
inline void Packet::htobll(char * p, long long val) {
|
||||
p[0] = (val >> 56) & 0xFF;
|
||||
p[1] = (val >> 48) & 0xFF;
|
||||
p[2] = (val >> 40) & 0xFF;
|
||||
p[3] = (val >> 32) & 0xFF;
|
||||
p[4] = (val >> 24) & 0xFF;
|
||||
p[5] = (val >> 16) & 0xFF;
|
||||
p[6] = (val >> 8) & 0xFF;
|
||||
p[7] = val & 0xFF;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Packet::sendRTCP(long long & connectedAt, void * socket, unsigned int tid , DTSC::Meta & metadata, void callBack(void *, char *, unsigned int, unsigned int)) {
|
||||
void * rtcpData = malloc(32);
|
||||
|
|
|
@ -28,10 +28,11 @@ namespace RTP {
|
|||
unsigned int datalen; ///<Size of rtp packet
|
||||
int sentPackets;
|
||||
int sentBytes;//Because ugly is beautiful
|
||||
inline void htobll(char * p, long long val);
|
||||
public:
|
||||
static double startRTCP;
|
||||
unsigned int getHsize() const;
|
||||
unsigned int getPayloadSize() const;
|
||||
char * getPayload() const;
|
||||
unsigned int getVersion() const;
|
||||
unsigned int getPadding() const;
|
||||
unsigned int getExtension() const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue