mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
donot mix the read and write for librtmp
This commit is contained in:
parent
1eee4d25cf
commit
a888e52df1
8 changed files with 58 additions and 16 deletions
|
@ -121,14 +121,14 @@ int process(const char* in_flv_file, const char* out_flv_file, srs_flv_t* pic, s
|
|||
srs_amf0_t amf0_data = NULL;
|
||||
srs_amf0_t filepositions = NULL;
|
||||
|
||||
if ((ic = srs_flv_open(in_flv_file)) == NULL) {
|
||||
if ((ic = srs_flv_open_read(in_flv_file)) == NULL) {
|
||||
ret = 2;
|
||||
trace("open input flv file failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
*pic = ic;
|
||||
|
||||
if ((oc = srs_flv_open(out_flv_file)) == NULL) {
|
||||
if ((oc = srs_flv_open_write(out_flv_file)) == NULL) {
|
||||
ret = 2;
|
||||
trace("open output flv file failed. ret=%d", ret);
|
||||
return ret;
|
||||
|
|
|
@ -64,7 +64,7 @@ int main(int argc, char** argv)
|
|||
trace("version: %d.%d.%d", srs_version_major(), srs_version_minor(), srs_version_revision());
|
||||
trace("input: %s", in_flv_file);
|
||||
|
||||
if ((flv = srs_flv_open(in_flv_file)) == NULL) {
|
||||
if ((flv = srs_flv_open_read(in_flv_file)) == NULL) {
|
||||
ret = 2;
|
||||
trace("open flv file failed. ret=%d", ret);
|
||||
return ret;
|
||||
|
|
|
@ -93,7 +93,7 @@ int main(int argc, char** argv)
|
|||
trace("input: %s", in_flv_file);
|
||||
trace("output: %s", out_rtmp_url);
|
||||
|
||||
if ((flv = srs_flv_open(in_flv_file)) == NULL) {
|
||||
if ((flv = srs_flv_open_read(in_flv_file)) == NULL) {
|
||||
ret = 2;
|
||||
trace("open flv file failed. ret=%d", ret);
|
||||
return ret;
|
||||
|
|
|
@ -120,6 +120,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#define ERROR_SYSTEM_CREATE_PIPE 430
|
||||
#define ERROR_SYSTEM_FILE_SEEK 431
|
||||
#define ERROR_SYSTEM_FLV_HEADER 432
|
||||
#define ERROR_SYSTEM_IO_INVALID 433
|
||||
|
||||
// see librtmp.
|
||||
// failed when open ssl create the dh
|
||||
|
|
|
@ -165,6 +165,11 @@ void SrsFileReader::close()
|
|||
return;
|
||||
}
|
||||
|
||||
bool SrsFileReader::is_open()
|
||||
{
|
||||
return fd > 0;
|
||||
}
|
||||
|
||||
int64_t SrsFileReader::tellg()
|
||||
{
|
||||
return (int64_t)::lseek(fd, 0, SEEK_CUR);
|
||||
|
|
|
@ -69,6 +69,7 @@ public:
|
|||
virtual int open(std::string file);
|
||||
virtual void close();
|
||||
public:
|
||||
virtual bool is_open();
|
||||
virtual int64_t tellg();
|
||||
virtual void skip(int64_t size);
|
||||
virtual int64_t lseek(int64_t offset);
|
||||
|
|
|
@ -467,7 +467,26 @@ struct FlvContext
|
|||
SrsFlvDecoder dec;
|
||||
};
|
||||
|
||||
srs_flv_t srs_flv_open(const char* file)
|
||||
srs_flv_t srs_flv_open_read(const char* file)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
FlvContext* flv = new FlvContext();
|
||||
|
||||
if ((ret = flv->reader.open(file)) != ERROR_SUCCESS) {
|
||||
srs_freep(flv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((ret = flv->dec.initialize(&flv->reader)) != ERROR_SUCCESS) {
|
||||
srs_freep(flv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return flv;
|
||||
}
|
||||
|
||||
srs_flv_t srs_flv_open_write(const char* file)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
|
@ -483,16 +502,6 @@ srs_flv_t srs_flv_open(const char* file)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if ((ret = flv->reader.open(file)) != ERROR_SUCCESS) {
|
||||
srs_freep(flv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((ret = flv->dec.initialize(&flv->reader)) != ERROR_SUCCESS) {
|
||||
srs_freep(flv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return flv;
|
||||
}
|
||||
|
||||
|
@ -507,6 +516,11 @@ int srs_flv_read_header(srs_flv_t flv, char header[9])
|
|||
int ret = ERROR_SUCCESS;
|
||||
|
||||
FlvContext* context = (FlvContext*)flv;
|
||||
|
||||
if (!context->reader.is_open()) {
|
||||
return ERROR_SYSTEM_IO_INVALID;
|
||||
}
|
||||
|
||||
if ((ret = context->dec.read_header(header)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -524,6 +538,11 @@ int srs_flv_read_tag_header(srs_flv_t flv, char* ptype, int32_t* pdata_size, u_i
|
|||
int ret = ERROR_SUCCESS;
|
||||
|
||||
FlvContext* context = (FlvContext*)flv;
|
||||
|
||||
if (!context->reader.is_open()) {
|
||||
return ERROR_SYSTEM_IO_INVALID;
|
||||
}
|
||||
|
||||
if ((ret = context->dec.read_tag_header(ptype, pdata_size, ptime)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -536,6 +555,11 @@ int srs_flv_read_tag_data(srs_flv_t flv, char* data, int32_t size)
|
|||
int ret = ERROR_SUCCESS;
|
||||
|
||||
FlvContext* context = (FlvContext*)flv;
|
||||
|
||||
if (!context->reader.is_open()) {
|
||||
return ERROR_SYSTEM_IO_INVALID;
|
||||
}
|
||||
|
||||
if ((ret = context->dec.read_tag_data(data, size)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -553,6 +577,11 @@ int srs_flv_write_header(srs_flv_t flv, char header[9])
|
|||
int ret = ERROR_SUCCESS;
|
||||
|
||||
FlvContext* context = (FlvContext*)flv;
|
||||
|
||||
if (!context->writer.is_open()) {
|
||||
return ERROR_SYSTEM_IO_INVALID;
|
||||
}
|
||||
|
||||
if ((ret = context->enc.write_header(header)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -565,6 +594,11 @@ int srs_flv_write_tag(srs_flv_t flv, char type, int32_t time, char* data, int si
|
|||
int ret = ERROR_SUCCESS;
|
||||
|
||||
FlvContext* context = (FlvContext*)flv;
|
||||
|
||||
if (!context->writer.is_open()) {
|
||||
return ERROR_SYSTEM_IO_INVALID;
|
||||
}
|
||||
|
||||
if (type == SRS_RTMP_TYPE_AUDIO) {
|
||||
return context->enc.write_audio(time, data, size);
|
||||
} else if (type == SRS_RTMP_TYPE_VIDEO) {
|
||||
|
|
|
@ -166,7 +166,8 @@ int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp);
|
|||
typedef void* srs_flv_t;
|
||||
typedef int flv_bool;
|
||||
/* open flv file for both read/write. */
|
||||
srs_flv_t srs_flv_open(const char* file);
|
||||
srs_flv_t srs_flv_open_read(const char* file);
|
||||
srs_flv_t srs_flv_open_write(const char* file);
|
||||
void srs_flv_close(srs_flv_t flv);
|
||||
/* read the flv header. 9bytes header. drop the 4bytes zero previous tag size */
|
||||
int srs_flv_read_header(srs_flv_t flv, char header[9]);
|
||||
|
|
Loading…
Reference in a new issue