Commit 1bfd14e6 authored by lucabe's avatar lucabe

Change avf_sdp_create() to get a pre-allocated buffer as input, and to

return an integer (0 if the SDP has been succesfully created, < 0 in case
of error)


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@9947 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent c8b34f5b
...@@ -842,12 +842,13 @@ int av_filename_number_test(const char *filename); ...@@ -842,12 +842,13 @@ int av_filename_number_test(const char *filename);
* multiple AVStreams (one AVStream per RTP stream). Otherwise, * multiple AVStreams (one AVStream per RTP stream). Otherwise,
* all the contexts in the array (an AVCodecContext per RTP stream) * all the contexts in the array (an AVCodecContext per RTP stream)
* must contain only one AVStream * must contain only one AVStream
* @param n_streams number of AVCodecContexts contained in ac * @param n_files number of AVCodecContexts contained in ac
* @return a pointer to the SDP (an array of chars which is allocated by * @param buff buffer where the SDP will be stored (must be allocated by
* avf_sdp_create(), and must be freed by the caller), or NULL in * the caller
* case of failure. * @param size the size of the buffer
* @return 0 if OK. AVERROR_xxx if error.
*/ */
char *avf_sdp_create(AVFormatContext *ac[], int n_streams); int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
#ifdef HAVE_AV_CONFIG_H #ifdef HAVE_AV_CONFIG_H
......
...@@ -169,19 +169,12 @@ static void sdp_write_media(char *buff, int size, AVCodecContext *c, const char ...@@ -169,19 +169,12 @@ static void sdp_write_media(char *buff, int size, AVCodecContext *c, const char
sdp_media_attributes(buff, size, c, payload_type); sdp_media_attributes(buff, size, c, payload_type);
} }
#define SDP_BUFFER_SIZE 2048 int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size)
char *avf_sdp_create(AVFormatContext *ac[], int n_files)
{ {
char *buff;
struct sdp_session_level s; struct sdp_session_level s;
int i, j, port, ttl; int i, j, port, ttl;
char dst[32]; char dst[32];
buff = av_mallocz(SDP_BUFFER_SIZE);
if (buff == NULL) {
return NULL;
}
memset(&s, 0, sizeof(struct sdp_session_level)); memset(&s, 0, sizeof(struct sdp_session_level));
s.user = "-"; s.user = "-";
s.src_addr = "127.0.0.1"; /* FIXME: Properly set this */ s.src_addr = "127.0.0.1"; /* FIXME: Properly set this */
...@@ -196,7 +189,7 @@ char *avf_sdp_create(AVFormatContext *ac[], int n_files) ...@@ -196,7 +189,7 @@ char *avf_sdp_create(AVFormatContext *ac[], int n_files)
s.ttl = ttl; s.ttl = ttl;
} }
} }
sdp_write_header(buff, SDP_BUFFER_SIZE, &s); sdp_write_header(buff, size, &s);
dst[0] = 0; dst[0] = 0;
for (i = 0; i < n_files; i++) { for (i = 0; i < n_files; i++) {
...@@ -204,21 +197,21 @@ char *avf_sdp_create(AVFormatContext *ac[], int n_files) ...@@ -204,21 +197,21 @@ char *avf_sdp_create(AVFormatContext *ac[], int n_files)
port = get_address(dst, sizeof(dst), &ttl, ac[i]->filename); port = get_address(dst, sizeof(dst), &ttl, ac[i]->filename);
} }
for (j = 0; j < ac[i]->nb_streams; j++) { for (j = 0; j < ac[i]->nb_streams; j++) {
sdp_write_media(buff, SDP_BUFFER_SIZE, sdp_write_media(buff, size,
ac[i]->streams[j]->codec, dst[0] ? dst : NULL, ac[i]->streams[j]->codec, dst[0] ? dst : NULL,
(port > 0) ? port + j * 2 : 0, ttl); (port > 0) ? port + j * 2 : 0, ttl);
if (port <= 0) { if (port <= 0) {
av_strlcatf(buff, SDP_BUFFER_SIZE, av_strlcatf(buff, size,
"a=control:streamid=%d\r\n", i + j); "a=control:streamid=%d\r\n", i + j);
} }
} }
} }
return buff; return 0;
} }
#else #else
char *avf_sdp_create(AVFormatContext *ac[], int n_files) int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size)
{ {
return NULL; return AVERROR(ENOSYS);
} }
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment