1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

for #738, add srs ingest mp4 tool

This commit is contained in:
winlin 2017-01-31 20:43:48 +08:00
parent 33ba6cdee2
commit 34a8eb6113
20 changed files with 366 additions and 274 deletions

View file

@ -25,6 +25,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <string.h>
#include <srs_kernel_error.hpp>
SrsMp4Box::SrsMp4Box()
{
size = 0;
@ -422,3 +424,19 @@ SrsMp4SampleSizeBox::~SrsMp4SampleSizeBox()
srs_freepa(entry_sizes);
}
SrsMp4Decoder::SrsMp4Decoder()
{
}
SrsMp4Decoder::~SrsMp4Decoder()
{
}
int SrsMp4Decoder::initialize(ISrsReader* r)
{
srs_assert(r);
reader = r;
return ERROR_SUCCESS;
}

View file

@ -31,6 +31,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <string>
class ISrsReader;
/**
* 4.2 Object Structure
* ISO_IEC_14496-12-base-format-2012.pdf, page 16
@ -760,5 +762,24 @@ public:
virtual ~SrsMp4SampleSizeBox();
};
/**
* The MP4 demuxer.
*/
class SrsMp4Decoder
{
private:
ISrsReader* reader;
public:
SrsMp4Decoder();
virtual ~SrsMp4Decoder();
public:
/**
* Initialize the decoder with a reader r.
* @param r The underlayer io reader, user must manage it for decoder never open/free it,
* the decoder just read data from the reader.
*/
virtual int initialize(ISrsReader* r);
};
#endif

View file

@ -49,6 +49,7 @@ using namespace std;
#include <srs_kernel_file.hpp>
#include <srs_lib_bandwidth.hpp>
#include <srs_raw_avc.hpp>
#include <srs_kernel_mp4.hpp>
// kernel module.
ISrsLog* _srs_log = new ISrsLog();
@ -1547,7 +1548,9 @@ srs_bool srs_h264_startswith_annexb(char* h264_raw_data, int h264_raw_size, int*
struct Mp4Context
{
bool non_seekable;
SrsFileReader reader;
SrsMp4Decoder dec;
};
srs_mp4_t srs_mp4_open_read(const char* file)
@ -1555,6 +1558,7 @@ srs_mp4_t srs_mp4_open_read(const char* file)
int ret = ERROR_SUCCESS;
Mp4Context* mp4 = new Mp4Context();
mp4->non_seekable = false;
if ((ret = mp4->reader.open(file)) != ERROR_SUCCESS) {
srs_freep(mp4);
@ -1569,6 +1573,22 @@ void srs_mp4_close(srs_mp4_t mp4)
Mp4Context* context = (Mp4Context*)mp4;
srs_freep(context);
}
int srs_mp4_init_demuxer(srs_mp4_t mp4)
{
int ret = ERROR_SUCCESS;
Mp4Context* context = (Mp4Context*)mp4;
if ((ret = context->dec.initialize(&context->reader)) != ERROR_SUCCESS) {
return ret;
}
// OK, it's legal mp4 for live streaming.
context->non_seekable = true;
return ret;
}
struct FlvContext
{

View file

@ -516,6 +516,12 @@ typedef void* srs_mp4_t;
/* Open mp4 file for muxer(write) or demuxer(read). */
extern srs_mp4_t srs_mp4_open_read(const char* file);
extern void srs_mp4_close(srs_mp4_t mp4);
/**
* Initialize mp4 demuxer in non-seek mode.
* @remark Only support non-seek mode, that is fmp4 or moov before mdata.
* For the live streaming, we must feed stream frame by frame.
*/
extern int srs_mp4_init_demuxer(srs_mp4_t mp4);
/*************************************************************
**************************************************************