mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix bug that only one stream can be encrypted..
This commit is contained in:
parent
52596a0b04
commit
43ebd5958d
3 changed files with 26 additions and 16 deletions
|
@ -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:
|
||||
|
||||
|
@ -171,6 +171,8 @@ private:
|
|||
unsigned char key[16];
|
||||
unsigned char iv[16];
|
||||
|
||||
SrsFileWriter *writer;
|
||||
|
||||
|
||||
private:
|
||||
int _sequence_no;
|
||||
|
|
|
@ -1578,18 +1578,17 @@ 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;
|
||||
|
||||
|
||||
class SrsEncFileWriter: public SrsFileWriter
|
||||
{
|
||||
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…
Add table
Add a link
Reference in a new issue