ameba micropython sdk first commit

This commit is contained in:
xidameng 2020-07-31 22:16:12 +08:00
commit 8508ee6139
5619 changed files with 1874619 additions and 0 deletions

View file

@ -0,0 +1,52 @@
#ifndef _MP4_DEMUXER_
typedef struct _header{
unsigned int size;
unsigned char str[4];
}header;
#define audio_bit 31
#define vkey_bit 30
#define mvhd_length 8
#define trak_length 8
#define mdia_length 8
#define minf_length 8
#define video_type 0
#define audio_type 1
typedef struct _mp4_demux{
FATFS m_fs;
int drv_num;
char _drv[4];
FIL m_file;
char filename[32];
int type;
unsigned int video_len;
unsigned int audio_len;
unsigned int key_len;
unsigned int sample_index;
unsigned int channel_count;
//unsigned int video_buf[2740][2];
//unsigned int audio_buf[2740][2];
//unsigned int (*video_buf)[2];
//unsigned int (*audio_buf)[2];
unsigned int (*all_buf)[2];
//unsigned int all_buf[3200][2];
unsigned int keyframe[100];
unsigned char sps[0x40];
unsigned char pps[0x10];
unsigned short sps_length;
unsigned short pps_length;
unsigned int mp4_index;
unsigned int total_len;
}mp4_demux,*pmp4_demux;
int get_video_trak(mp4_demux *mp4_demuxer,int index);
int get_audio_trak(mp4_demux *mp4_demuxer,int index);
void create_adts_header(int rate_idx,int channels,int length,unsigned char *adts_header);
int ccompare( const void *a , const void *b );
FRESULT fseek ( FIL * stream, long int offset, int origin );
FRESULT fread ( void * ptr, size_t size, size_t count, FIL * stream );
FRESULT fwrite ( const void * ptr, size_t size, size_t count, FIL * stream );
#endif

View file

@ -0,0 +1,114 @@
#ifndef _MP4_ENCAP_H_
#define _MP4_ENCAP_H_
#include "basic_types.h"
#include "osdep_service.h"
#define MAX_BOX_CHILD 8
#define RBUF_SIZE 1024
typedef struct _mp4root{
unsigned int video_len;
unsigned int audio_len;
unsigned int total;
unsigned int keyindex;
}MP4root,*PMP4root;
#define STORAGE_IDLE 0
#define STORAGE_START 1
#define STORAGE_WRITE_ALL 2
#define STORAGE_WRITE_VIDEO 3
#define STORAGE_WRITE_AUDIO 4
#define STORAGE_STOP 5
#define STORAGE_END 6
#define STORAGE_ALL 0
#define STORAGE_VIDEO 1
#define STORAGE_AUDIO 2
typedef struct _mp4_payload{
unsigned char *addr;
unsigned int len;
}mp4_payload,pmp4_payload;
typedef struct _mp4_write_info{
int mp4_start_position;
int mp4_end_position;
int mp4_occupy_size;
int mp4_empty_size;
int mp4_write_start_position;
int mp4_write_end_position;
int mp4_write_occupy_size;
int mp4_write_empty_size;
int mp4_write_length;
}mp4_winfo,*pmp4_winfo;
typedef struct _mp4_context{
FATFS m_fs;
int drv_num;
char _drv[4];
FIL m_file;
char filename[32];
int Fatfs_ok;
int filecount;
int width;
int height;
int sample_rate;
int channel_count;
int frame_rate;
u32 start_time;//rtw_get_current_time()
u32 file_name_index;
u32 storage_state;
MP4root root;
MP4root root_reserve;
int period_time;
int file_total;
int sps_start;
int type;
int sps_len;
int pps_len;
int sps_pps_mark;
unsigned int *video_buffer_index;
unsigned int *video_buffer_size;
int video_size;
unsigned int *audio_buffer_index;
unsigned int *audio_buffer_size;
int audio_size;
unsigned char *moov_box;
int moov_box_size;
unsigned char *h264_buf;
int H264_LENGTH;
mp4_payload payload;
mp4_payload reserved_payload;
int reserved_start_index;
int iframe;
int reserved_type;
_sema start_fatfs_write;
int write_status;
int audio_write_status;
int video_write_status;
int buffer_write_status;//0: real write 1: virtual write
mp4_winfo winfo;
int nal_len;
int h264_extra_len;
int mp4_muxer_enable;
int (*cb_start)(void*); // start recording
int (*cb_stop)(void*); // stop recording
}mp4_context,*pmp4_context;
#define IDLE 0
#define FATFS_WRITING 1
#define FATFS_DONE 2
void mp4_handle(pmp4_context mp4_ctx,unsigned char *buf,unsigned int size,int type);
void set_mp4_audio_buffer(pmp4_context mp4_ctx,unsigned int *audio_index,unsigned int *audio_size,int size);
void set_mp4_video_buffer(pmp4_context mp4_ctx,unsigned int *video_index,unsigned int *video_size,int size);
void set_mp4_moov_buffer(pmp4_context mp4_ctx,unsigned char *moov,int size);
int mp4_set_record(pmp4_context mp4_ctx,int num);
void mp4_muxer_init(pmp4_context mp4_ctx);
void mp4_muxer_close(pmp4_context mp4_ctx);
int mp4_set_start_status(pmp4_context mp4_ctx);
int mp4_set_stop_status(pmp4_context mp4_ctx);
#endif

View file

@ -0,0 +1,106 @@
#ifndef _MP4_MUXER_H_
#define _MP4_MUXER_H_
#include "basic_types.h"
#include "osdep_service.h"
#include "fatfs_sdcard_api.h"
#define MAX_BOX_CHILD 8
#define RBUF_SIZE 1024
typedef struct _mp4root{
unsigned int video_len;
unsigned int audio_len;
unsigned int total;
unsigned int keyindex;
}MP4root,*PMP4root;
#define STORAGE_IDLE 0
#define STORAGE_INIT 1
#define STORAGE_START 2
#define STORAGE_WRITE_ALL 3
#define STORAGE_WRITE_VIDEO 4
#define STORAGE_WRITE_AUDIO 5
#define STORAGE_STOP 6
#define STORAGE_ALL 0
#define STORAGE_VIDEO 1
#define STORAGE_AUDIO 2
typedef struct _mp4_payload{
unsigned char *addr;
unsigned int len;
}mp4_payload,pmp4_payload;
typedef struct _mp4_context{
FATFS m_fs;
int drv_num;
char _drv[4];
FIL m_file;
char filename[32];
int Fatfs_ok;
int filecount;
int width;
int height;
int sample_rate;
int channel_count;
int frame_rate;
int gop;
u32 start_time;//rtw_get_current_time()
u32 file_name_index;
u32 storage_state;
MP4root root;
int period_time;
int file_total;
int sps_start;
int type;
int sps_len;
int pps_len;
int sps_pps_mark;
unsigned int *video_buffer_index;
unsigned int *video_buffer_size;
unsigned int video_size;
unsigned int *key_frame;
unsigned int key_frame_size;
unsigned int *audio_buffer_index;
unsigned int *audio_buffer_size;
unsigned int audio_size;
unsigned char *moov_box;
unsigned int moov_box_size;
unsigned char *fatfs_buf;
unsigned int fatfs_buf_size;
unsigned int fatfs_buf_pos;
mp4_payload payload;
int write_status;
int nal_len;
int h264_extra_len;
char sps_str[64];
char pps_str[64];
unsigned char ftyp_box[24];
unsigned char mdat_box[8];
int audio_clock_rate;
int video_clock_rate;
unsigned int video_old_depend_clock_tick;
unsigned int audio_old_depend_clock_tick;
unsigned int video_timestamp;
unsigned int audio_timestamp;
unsigned int video_timestamp_first;
unsigned int audio_timestamp_first;
unsigned int *video_timestamp_buffer;
unsigned int *audio_timestamp_buffer;
int (*cb_start)(void*);
int (*cb_stop)(void*);
int (*cb_end)(void*);
int loop_mode;
}mp4_context,*pmp4_context;
void mp4_muxer_init(pmp4_context mp4_ctx);
void mp4_muxer_close(pmp4_context mp4_ctx);
void set_mp4_fatfs_param(pmp4_context mp4_ctx, fatfs_sd_params_t* fatfs_param);
u8 mp4_is_recording(pmp4_context mp4_ctx);
int mp4_start_record(pmp4_context mp4_ctx, int file_num);
int mp4_stop_record(pmp4_context mp4_ctx);
void mp4_muxer_handle(pmp4_context mp4_ctx,unsigned char *buf,unsigned int size,int type,unsigned int timestamp);
#endif //_MP4_MUXER_H_