Skip to content

Commit

Permalink
fix: fmp4_writer_write return with file write error
Browse files Browse the repository at this point in the history
  • Loading branch information
ireader committed Aug 28, 2021
1 parent b12546b commit 2a28db2
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 21 deletions.
4 changes: 2 additions & 2 deletions libdash/src/dash-mpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ static int mov_buffer_seek(void* param, int64_t offset)
return 0;
}

static uint64_t mov_buffer_tell(void* param)
static int64_t mov_buffer_tell(void* param)
{
return ((struct dash_adaptation_set_t*)param)->offset;
return (int64_t)((struct dash_adaptation_set_t*)param)->offset;
}

static struct mov_buffer_t s_io = {
Expand Down
4 changes: 2 additions & 2 deletions libhls/source/hls-fmp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ static int mov_buffer_seek(void* param, int64_t offset)
return 0;
}

static uint64_t mov_buffer_tell(void* param)
static int64_t mov_buffer_tell(void* param)
{
return ((struct hls_fmp4_t*)param)->offset;
return (int64_t)((struct hls_fmp4_t*)param)->offset;
}

static struct mov_buffer_t s_io = {
Expand Down
4 changes: 2 additions & 2 deletions libmkv/include/mkv-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ struct mkv_buffer_t
int (*seek)(void* param, int64_t offset);

/// get buffer read/write position
/// @return >=0-current read/write position
uint64_t (*tell)(void* param);
/// @return <0-error, other-current read/write position
int64_t (*tell)(void* param);
};

struct mkv_file_cache_t
Expand Down
6 changes: 5 additions & 1 deletion libmkv/src/mkv-ioutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ static inline int mkv_buffer_error(const struct mkv_ioutil_t* io)

static inline uint64_t mkv_buffer_tell(const struct mkv_ioutil_t* io)
{
return io->io.tell(io->param);
int64_t v;
v = io->io.tell(io->param);
if (v < 0)
((struct mkv_ioutil_t*)io)->error = -1;
return v;
}

static inline void mkv_buffer_seek(const struct mkv_ioutil_t* io, uint64_t offset)
Expand Down
9 changes: 5 additions & 4 deletions libmkv/test/mkv-file-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static int mkv_file_seek(void* fp, int64_t offset)
return fseek64((FILE*)fp, offset, offset >= 0 ? SEEK_SET : SEEK_END);
}

static uint64_t mkv_file_tell(void* fp)
static int64_t mkv_file_tell(void* fp)
{
return ftell64((FILE*)fp);
}
Expand Down Expand Up @@ -124,11 +124,12 @@ static int mkv_file_cache_seek(void* fp, int64_t offset)
return 0;
}

static uint64_t mkv_file_cache_tell(void* fp)
static int64_t mkv_file_cache_tell(void* fp)
{
struct mkv_file_cache_t* file = (struct mkv_file_cache_t*)fp;
assert(ftell64(file->fp) == file->tell + (int)(file->len - file->off));
return file->tell;
if (ftell64(file->fp) != file->tell + (int)(file->len - file->off))
return -1;
return (int64_t)file->tell;
//return ftell64(file->fp);
}

Expand Down
4 changes: 2 additions & 2 deletions libmov/include/mov-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ struct mov_buffer_t
int (*seek)(void* param, int64_t offset);

/// get buffer read/write position
/// @return current read/write position
uint64_t (*tell)(void* param);
/// @return <0-error, other-current read/write position
int64_t (*tell)(void* param);
};

#endif /* !_mov_buffer_h_ */
4 changes: 2 additions & 2 deletions libmov/include/mov-memory-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ static int mov_memory_seek(void* param, int64_t offset)
return 0;
}

static uint64_t mov_memory_tell(void* param)
static int64_t mov_memory_tell(void* param)
{
struct mov_memory_buffer_t* ptr;
ptr = (struct mov_memory_buffer_t*)param;
return ptr->off;
return (int64_t)ptr->off;
}

static inline const struct mov_buffer_t* mov_memory_buffer(void)
Expand Down
2 changes: 1 addition & 1 deletion libmov/source/fmp4-writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ int fmp4_writer_write(struct fmp4_writer_t* writer, int idx, const void* data, s
writer->mdat_size += bytes; // update media data size
track->sample_count += 1;
track->last_dts = sample->dts;
return 0;
return mov_buffer_error(&writer->mov.io);
}

int fmp4_writer_add_audio(struct fmp4_writer_t* writer, uint8_t object, int channel_count, int bits_per_sample, int sample_rate, const void* extra_data, size_t extra_data_size)
Expand Down
6 changes: 5 additions & 1 deletion libmov/source/mov-ioutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ static inline int mov_buffer_error(const struct mov_ioutil_t* io)

static inline uint64_t mov_buffer_tell(const struct mov_ioutil_t* io)
{
return io->io.tell(io->param);
int64_t v;
v = io->io.tell(io->param);
if (v < 0)
((struct mov_ioutil_t*)io)->error = -1;
return v;
}

static inline void mov_buffer_seek(const struct mov_ioutil_t* io, int64_t offset)
Expand Down
9 changes: 5 additions & 4 deletions libmov/test/mov-file-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static int mov_file_seek(void* fp, int64_t offset)
return fseek64((FILE*)fp, offset, offset >= 0 ? SEEK_SET : SEEK_END);
}

static uint64_t mov_file_tell(void* fp)
static int64_t mov_file_tell(void* fp)
{
return ftell64((FILE*)fp);
}
Expand Down Expand Up @@ -126,11 +126,12 @@ static int mov_file_cache_seek(void* fp, int64_t offset)
return 0;
}

static uint64_t mov_file_cache_tell(void* fp)
static int64_t mov_file_cache_tell(void* fp)
{
struct mov_file_cache_t* file = (struct mov_file_cache_t*)fp;
assert(ftell64(file->fp) == file->tell + (int)(file->len - file->off));
return file->tell;
if (ftell64(file->fp) != file->tell + (int)(file->len - file->off))
return -1;
return (int64_t)file->tell;
//return ftell64(file->fp);
}

Expand Down

0 comments on commit 2a28db2

Please sign in to comment.