fix bug that only one stream can be encrypted..

pull/1106/head
Harlan 7 years ago
parent 52596a0b04
commit 43ebd5958d

@ -62,18 +62,11 @@ using namespace std;
// reset the piece id when deviation overflow this.
#define SRS_JUMP_WHEN_PIECE_DEVIATION 20
SrsHlsSegment::SrsHlsSegment(SrsTsContext* c, SrsAudioCodecId ac, SrsVideoCodecId vc,bool needenc)
SrsHlsSegment::SrsHlsSegment(SrsTsContext* c, SrsAudioCodecId ac, SrsVideoCodecId vc, SrsFileWriter *srswriter)
{
sequence_no = 0;
if(needenc)
{
writer = new SrsEncFileWriter();
}
else
{
writer = new SrsFileWriter();
}
writer = srswriter;
tscw = new SrsTsContextWriter(writer, c, ac, vc);
}
@ -87,7 +80,7 @@ void SrsHlsSegment::SrsSetEncCfg(unsigned char* keyval,unsigned char *ivval)
SrsHlsSegment::~SrsHlsSegment()
{
srs_freep(tscw);
srs_freep(writer);
//srs_freep(writer);
}
SrsDvrAsyncCallOnHls::SrsDvrAsyncCallOnHls(int c, SrsRequest* r, string p, string t, string m, string mu, int s, double d)
@ -223,6 +216,7 @@ SrsHlsMuxer::~SrsHlsMuxer()
srs_freep(req);
srs_freep(async);
srs_freep(context);
srs_freep(writer);
}
void SrsHlsMuxer::dispose()
@ -335,6 +329,15 @@ srs_error_t SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix,
}
}
if(hls_keys)
{
writer = new SrsEncFileWriter();
}
else
{
writer = new SrsFileWriter();
}
return err;
}
@ -379,7 +382,7 @@ srs_error_t SrsHlsMuxer::segment_open()
}
// new segment.
current = new SrsHlsSegment(context, default_acodec, default_vcodec, hls_keys);
current = new SrsHlsSegment(context, default_acodec, default_vcodec,writer);
current->sequence_no = _sequence_no++;
if(hls_keys){

@ -73,7 +73,7 @@ public:
std::string keypath;
public:
SrsHlsSegment(SrsTsContext* c, SrsAudioCodecId ac, SrsVideoCodecId vc,bool needenc);
SrsHlsSegment(SrsTsContext* c, SrsAudioCodecId ac, SrsVideoCodecId vc, SrsFileWriter *srswriter);
virtual ~SrsHlsSegment();
public:
@ -170,6 +170,8 @@ private:
unsigned char key[16];
unsigned char iv[16];
SrsFileWriter *writer;
private:

@ -1578,11 +1578,8 @@ public:
* Used for HLS Encryption
*/
#define HLS_AES_ENCRYPT_BLOCK_LENGTH 188*4
static char tmpbuf[HLS_AES_ENCRYPT_BLOCK_LENGTH] = {0};
static int buflength = 0;
#define HLS_AES_ENCRYPT_BLOCK_LENGTH 188*4
class SrsEncFileWriter: public SrsFileWriter
{
@ -1590,6 +1587,8 @@ public:
SrsEncFileWriter()
{
memset(iv,0,16);
memset(tmpbuf,0,HLS_AES_ENCRYPT_BLOCK_LENGTH);
buflength = 0;
}
virtual ~SrsEncFileWriter(){}
@ -1602,6 +1601,12 @@ public:
private:
AES_KEY key;
unsigned char iv[16];
private:
char tmpbuf[HLS_AES_ENCRYPT_BLOCK_LENGTH];
int buflength;
};
/**

Loading…
Cancel
Save