Luca Abeni <[EMAIL PROTECTED]> added the comment:
Here is the patch for H.264 support in the SDP generator
______________________________________________________
FFmpeg issue tracker <[EMAIL PROTECTED]>
<https://roundup.mplayerhq.hu/roundup/ffmpeg/issue306>
______________________________________________________
Index: ffmpeg/libavformat/sdp.c
===================================================================
--- ffmpeg.orig/libavformat/sdp.c 2007-11-16 12:43:37.000000000 +0100
+++ ffmpeg/libavformat/sdp.c 2007-11-16 13:04:39.000000000 +0100
@@ -21,6 +21,8 @@
#include "avstring.h"
#include "avformat.h"
#include "rtp.h"
+#include "rtp_h264.h"
+#include "base64.h"
#ifdef CONFIG_RTP_MUXER
#define MAX_EXTRADATA_SIZE ((INT_MAX - 10) / 2)
@@ -111,6 +113,48 @@
return buff;
}
+static char *extradata2psets(const uint8_t *extradata, int extradata_size)
+{
+ char *psets, *p;
+ const uint8_t *r;
+
+ if (extradata_size > MAX_EXTRADATA_SIZE) {
+ av_log(NULL, AV_LOG_ERROR, "Too many extra data!\n");
+
+ return NULL;
+ }
+
+ psets = av_mallocz(1024);
+ if (psets == NULL) {
+ av_log(NULL, AV_LOG_ERROR, "Cannot allocate memory for the parameter sets\n");
+ return NULL;
+ }
+ memcpy(psets, "; sprop-parameter-sets=", 23);
+ p = psets + 23;
+ r = extradata;
+ while (r) {
+ int nal_size = extradata_size - (r - extradata);
+
+ r = ff_nal_get(r, &nal_size);
+ if (r) {
+ if (p != (psets + 23)) {
+ *p = ',';
+ p++;
+ }
+ if (av_base64_encode(p, 1024 - (p - psets), r, nal_size) == NULL) {
+ av_log(NULL, AV_LOG_ERROR, "Cannot BASE64 encode!\n");
+ av_free(psets);
+
+ return NULL;
+ }
+ p += strlen(p);
+ r += nal_size;
+ }
+ }
+
+ return psets;
+}
+
static char *extradata2config(const uint8_t *extradata, int extradata_size)
{
char *config;
@@ -137,6 +181,17 @@
char *config = NULL;
switch (c->codec_id) {
+ case CODEC_ID_H264:
+ if (c->extradata_size) {
+ config = extradata2psets(c->extradata, c->extradata_size);
+ }
+ av_strlcatf(buff, size, "a=rtpmap:%d H264/90000\r\n"
+ "a=fmtp:%d packetization-mode=1%s\r\n",
+/* "profile-level-id=%x%s\r\n", */
+ payload_type,
+ payload_type, /*profile_level_id, */
+ config ? config : "");
+ break;
case CODEC_ID_MPEG4:
if (c->extradata_size) {
config = extradata2config(c->extradata, c->extradata_size);
Index: ffmpeg/libavformat/rtp_h264.c
===================================================================
--- ffmpeg.orig/libavformat/rtp_h264.c 2007-11-16 12:53:43.000000000 +0100
+++ ffmpeg/libavformat/rtp_h264.c 2007-11-16 13:04:07.000000000 +0100
@@ -400,6 +400,39 @@
return 0; // keep processing it the normal way...
}
+static int nal_start(const uint8_t *p)
+{
+ if ((p[0] == 0x00) && (p[1] == 0x00) && (p[2] == 0x00) && (p[3] == 0x01)) {
+ return 4;
+ }
+ if ((p[0] == 0x00) && (p[1] == 0x00) && (p[2] == 0x01)) {
+ return 3;
+ }
+
+ return 0;
+}
+
+const uint8_t *ff_nal_get(const uint8_t *buf, int *size)
+{
+ int len = nal_start(buf);
+
+ if (len) {
+ const uint8_t *r1, *r = buf + len;
+
+ for(r1 = r; r1 < buf + *size; r1++) {
+ len = nal_start(r1);
+ if (len) {
+ break;
+ }
+ }
+
+ *size = r1 - r;
+ return r;
+ }
+
+ return NULL;
+}
+
/**
This is the structure for expanding on the dynamic rtp protocols (makes everything static. yay!)
*/
Index: ffmpeg/libavformat/rtp_h264.h
===================================================================
--- ffmpeg.orig/libavformat/rtp_h264.h 2007-11-16 12:53:43.000000000 +0100
+++ ffmpeg/libavformat/rtp_h264.h 2007-11-16 12:54:40.000000000 +0100
@@ -25,5 +25,6 @@
#include "rtp_internal.h"
extern RTPDynamicProtocolHandler ff_h264_dynamic_handler;
+const uint8_t *ff_nal_get(const uint8_t *buf, int *size);
#endif /* FFMPEG_RTP_H264_H */