-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
2,396 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
components/3rd_party/media_server/inc/h265-camera-source.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#ifndef _h265_camera_source_h_ | ||
#define _h265_camera_source_h_ | ||
|
||
#include "media-source.h" | ||
#include "sys/process.h" | ||
#include "time64.h" | ||
#include "rtp.h" | ||
#include <string> | ||
#include "pthread.h" | ||
#include <list> | ||
|
||
class H265CameraSource : public IMediaSource | ||
{ | ||
public: | ||
H265CameraSource(const char *file); | ||
virtual ~H265CameraSource(); | ||
|
||
public: | ||
virtual int Play(); | ||
virtual int Pause(); | ||
virtual int Seek(int64_t pos); | ||
virtual int SetSpeed(double speed); | ||
virtual int GetDuration(int64_t& duration) const; | ||
virtual int GetSDPMedia(std::string& sdp) const; | ||
virtual int GetRTPInfo(const char* uri, char *rtpinfo, size_t bytes) const; | ||
virtual int SetTransport(const char* track, std::shared_ptr<IRTPTransport> transport); | ||
int SetNextFrame(const uint8_t* ptr, size_t bytes); | ||
|
||
private: | ||
int GetNextFrame(int64_t &dts, const uint8_t* &ptr, size_t &bytes); | ||
int FreeNextFrame(); | ||
|
||
static void OnRTCPEvent(void* param, const struct rtcp_msg_t* msg); | ||
void OnRTCPEvent(const struct rtcp_msg_t* msg); | ||
int SendRTCP(); | ||
|
||
static void* RTPAlloc(void* param, int bytes); | ||
static void RTPFree(void* param, void *packet); | ||
static int RTPPacket(void* param, const void *packet, int bytes, uint32_t timestamp, int flags); | ||
|
||
private: | ||
void* m_rtp; | ||
uint32_t m_timestamp; | ||
time64_t m_rtp_clock; | ||
time64_t m_rtcp_clock; | ||
// H265CameraReader m_reader; | ||
std::shared_ptr<IRTPTransport> m_transport; | ||
|
||
struct vframe_t | ||
{ | ||
const uint8_t* nalu; | ||
int64_t time; | ||
long bytes; | ||
bool idr; // IDR frame | ||
|
||
bool operator < (const struct vframe_t &v) const | ||
{ | ||
return time < v.time; | ||
} | ||
}; | ||
typedef std::list<vframe_t> lframes_t; | ||
lframes_t m_videos_list; | ||
lframes_t::iterator m_video; | ||
pthread_mutex_t m_lock; | ||
|
||
std::list<std::pair<const uint8_t*, size_t> > m_sps; | ||
|
||
int m_status; | ||
int64_t m_pos; | ||
double m_speed; | ||
|
||
void *m_rtppacker; | ||
unsigned char m_packet[MAX_UDP_PACKET+14]; | ||
}; | ||
|
||
#endif /* !_h265_camera_source_h_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef _media_source_h_ | ||
#define _media_source_h_ | ||
|
||
#include <string> | ||
#include <memory> | ||
|
||
#ifndef MAX_UDP_PACKET | ||
#define MAX_UDP_PACKET (1450-16) | ||
#endif | ||
|
||
struct IRTPTransport | ||
{ | ||
virtual int Send(bool rtcp, const void* data, size_t bytes) = 0; | ||
}; | ||
|
||
struct IMediaSource | ||
{ | ||
virtual ~IMediaSource(){} | ||
|
||
virtual int Play() = 0; | ||
virtual int Pause() = 0; | ||
virtual int Seek(int64_t pos) = 0; | ||
virtual int SetSpeed(double speed) = 0; | ||
virtual int GetDuration(int64_t& duration) const = 0; | ||
virtual int GetSDPMedia(std::string& sdp) const = 0; | ||
virtual int GetRTPInfo(const char* uri, char *rtpinfo, size_t bytes) const = 0; | ||
virtual int SetTransport(const char* track, std::shared_ptr<IRTPTransport> transport) = 0; | ||
}; | ||
|
||
#endif /* !_media_source_h_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef _rtp_tcp_transport_h_ | ||
#define _rtp_tcp_transport_h_ | ||
|
||
#include "media-source.h" | ||
#include "rtsp-server-internal.h" | ||
|
||
class RTPTcpTransport : public IRTPTransport | ||
{ | ||
public: | ||
RTPTcpTransport(rtsp_server_t* rtsp, uint8_t rtp, uint8_t rtcp): m_rtp(rtp), m_rtcp(rtcp), m_rtsp(rtsp) {} | ||
virtual ~RTPTcpTransport() {} | ||
|
||
public: | ||
virtual int Send(bool rtcp, const void* data, size_t bytes) | ||
{ | ||
assert(bytes < (1 << 16)); | ||
if (bytes >= (1 << 16)) | ||
return -E2BIG; | ||
|
||
m_packet[0] = '$'; | ||
m_packet[1] = rtcp ? m_rtcp : m_rtp; | ||
m_packet[2] = (bytes >> 8) & 0xFF; | ||
m_packet[3] = bytes & 0xff; | ||
memcpy(m_packet + 4, data, bytes); | ||
int r = rtsp_server_send_interleaved_data(m_rtsp, m_packet, bytes + 4); | ||
return 0 == r ? bytes : r; | ||
} | ||
|
||
private: | ||
uint8_t m_rtp; | ||
uint8_t m_rtcp; | ||
rtsp_server_t* m_rtsp; | ||
uint8_t m_packet[4 + (1 << 16)]; | ||
}; | ||
|
||
#endif /* !_rtp_tcp_transport_h_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef _rtp_udp_transport_h_ | ||
#define _rtp_udp_transport_h_ | ||
|
||
#include "sys/sock.h" | ||
#include "media-source.h" | ||
|
||
class RTPUdpTransport : public IRTPTransport | ||
{ | ||
public: | ||
RTPUdpTransport(); | ||
virtual ~RTPUdpTransport(); | ||
|
||
public: | ||
virtual int Send(bool rtcp, const void* data, size_t bytes); | ||
|
||
public: | ||
int Init(const char* ip, unsigned short port[2]); | ||
int Init(socket_t socket[2], const char* peer, unsigned short port[2]); | ||
|
||
private: | ||
socket_t m_socket[2]; | ||
socklen_t m_addrlen[2]; | ||
struct sockaddr_storage m_addr[2]; | ||
}; | ||
|
||
#endif /* !_rtp_udp_transport_h_ */ |
49 changes: 49 additions & 0 deletions
49
components/3rd_party/media_server/inc/rtsp-server-internal.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#ifndef _rtsp_server_internal_h_ | ||
#define _rtsp_server_internal_h_ | ||
|
||
#include "rtsp-server.h" | ||
#include "http-parser.h" | ||
#include "rtsp-header-session.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <assert.h> | ||
|
||
#if defined(OS_WINDOWS) | ||
#define strcasecmp _stricmp | ||
#endif | ||
|
||
#define MAX_UDP_PACKAGE 1024 | ||
|
||
#define USER_AGENT "ireader/media-server" | ||
|
||
struct rtsp_server_t | ||
{ | ||
struct rtsp_handler_t handler; | ||
void *param, *sendparam; | ||
|
||
http_parser_t* parser; | ||
struct rtsp_header_session_t session; | ||
|
||
unsigned int cseq; | ||
char reply[MAX_UDP_PACKAGE]; | ||
|
||
char ip[65]; // IPv4/IPv6 | ||
unsigned short port; | ||
}; | ||
|
||
int rtsp_server_handle(struct rtsp_server_t *rtsp); | ||
int rtsp_server_options(struct rtsp_server_t *rtsp, const char* uri); | ||
int rtsp_server_announce(struct rtsp_server_t *rtsp, const char* uri); | ||
int rtsp_server_describe(struct rtsp_server_t *rtsp, const char* uri); | ||
int rtsp_server_setup(struct rtsp_server_t *rtsp, const char* uri); | ||
int rtsp_server_play(struct rtsp_server_t *rtsp, const char* uri); | ||
int rtsp_server_pause(struct rtsp_server_t *rtsp, const char* uri); | ||
int rtsp_server_teardown(struct rtsp_server_t *rtsp, const char* uri); | ||
int rtsp_server_get_parameter(struct rtsp_server_t *rtsp, const char* uri); | ||
int rtsp_server_set_parameter(struct rtsp_server_t *rtsp, const char* uri); | ||
int rtsp_server_record(struct rtsp_server_t *rtsp, const char* uri); | ||
int rtsp_server_reply(struct rtsp_server_t *rtsp, int code); | ||
int rtsp_server_reply2(struct rtsp_server_t *rtsp, int code, const char* header, const void* data, int bytes); | ||
|
||
#endif /* !_rtsp_server_internal_h_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef __RTSP_SERVER_H | ||
#define __RTSP_SERVER_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "stdlib.h" | ||
#include "stdint.h" | ||
|
||
int rtsp_server_init(char *ip, int port); | ||
int rtsp_server_deinit(void); | ||
char *rtsp_get_server_ip(void); | ||
int rtsp_get_server_port(void); | ||
int rtsp_server_start(void); | ||
int rtsp_server_stop(void); | ||
void rtsp_send_h265_data(uint8_t *asddata, size_t data_len); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // __RTSP_SERVER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1 @@ | ||
# readme | ||
|
||
对openmv库进行了代码裁剪,保证代码量尽量的小,以方便在出现问题时可以快速定位到是否是移植带来的问题。 | ||
|
||
其中主要修改的部分: | ||
1. alloc文件用于内存管理,由于openmv的内存管理与板级强相关,所以这里的实现与源码有差异 | ||
2. common文件用于存放一些通用函数。这里删除掉了大部分用不到的文件,只保留了一些方便imlib编译通过的文件。删除大部分文件的优势是可以更快的理解imlib依赖的代码,缺点是如果源码库中common文件有更新,需要手动同步到这里 | ||
3. imlib文件用于存放imlib的核心代码 | ||
4. ports文件保存了配置文件、与板级相关的代码、与第三方库相关的代码 | ||
|
||
|
||
# TODO: | ||
|
||
1. 未实现文件操作功能。在ports/linux中添加了oofatfs只是为了编译通过,实际上并没有实现文件操作功能 |
Oops, something went wrong.