Message ID | 1424727122-2827-6-git-send-email-martin@martin.st |
---|---|
State | Committed |
Commit | 353b492d0f2a21ae8eb829db1ac01b54b2a4d202 |
Headers | show |
On 23/02/15 22:31, Martin Storsjö wrote: > This avoids allocating space for a too large buffer for all the > name strings. > --- > libavformat/rtpdec.c | 3 ++- > libavformat/rtpdec.h | 2 +- > 2 files changed, 3 insertions(+), 2 deletions(-) > > diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c > index f040ea6..d0b25bc 100644 > --- a/libavformat/rtpdec.c > +++ b/libavformat/rtpdec.c > @@ -113,7 +113,8 @@ RTPDynamicProtocolHandler *ff_rtp_handler_find_by_name(const char *name, > RTPDynamicProtocolHandler *handler; > for (handler = rtp_first_dynamic_payload_handler; > handler; handler = handler->next) > - if (!av_strcasecmp(name, handler->enc_name) && > + if (handler->enc_name && > + !av_strcasecmp(name, handler->enc_name) && > codec_type == handler->codec_type) > return handler; > return NULL; > diff --git a/libavformat/rtpdec.h b/libavformat/rtpdec.h > index 46b08ce..9f1a475 100644 > --- a/libavformat/rtpdec.h > +++ b/libavformat/rtpdec.h > @@ -113,7 +113,7 @@ typedef int (*DynamicPayloadPacketHandlerProc)(AVFormatContext *ctx, > int len, uint16_t seq, int flags); > > struct RTPDynamicProtocolHandler { > - const char enc_name[50]; > + const char *enc_name; > enum AVMediaType codec_type; > enum AVCodecID codec_id; > int static_payload_id; /* 0 means no payload id is set. 0 is a valid > Where is it allocated? lu
On Mon, 23 Feb 2015, Luca Barbato wrote: > On 23/02/15 22:31, Martin Storsjö wrote: >> This avoids allocating space for a too large buffer for all the >> name strings. >> --- >> libavformat/rtpdec.c | 3 ++- >> libavformat/rtpdec.h | 2 +- >> 2 files changed, 3 insertions(+), 2 deletions(-) >> >> diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c >> index f040ea6..d0b25bc 100644 >> --- a/libavformat/rtpdec.c >> +++ b/libavformat/rtpdec.c >> @@ -113,7 +113,8 @@ RTPDynamicProtocolHandler > *ff_rtp_handler_find_by_name(const char *name, >> RTPDynamicProtocolHandler *handler; >> for (handler = rtp_first_dynamic_payload_handler; >> handler; handler = handler->next) >> - if (!av_strcasecmp(name, handler->enc_name) && >> + if (handler->enc_name && >> + !av_strcasecmp(name, handler->enc_name) && >> codec_type == handler->codec_type) >> return handler; >> return NULL; >> diff --git a/libavformat/rtpdec.h b/libavformat/rtpdec.h >> index 46b08ce..9f1a475 100644 >> --- a/libavformat/rtpdec.h >> +++ b/libavformat/rtpdec.h >> @@ -113,7 +113,7 @@ typedef int > (*DynamicPayloadPacketHandlerProc)(AVFormatContext *ctx, >> int len, uint16_t seq, int > flags); >> >> struct RTPDynamicProtocolHandler { >> - const char enc_name[50]; >> + const char *enc_name; >> enum AVMediaType codec_type; >> enum AVCodecID codec_id; >> int static_payload_id; /* 0 means no payload id is set. 0 is a valid >> > > Where is it allocated? They are just statically allocated const strings, like this in the structs: .enc_name = "foo", So instead of preallocating a specific size for these (which either can turn out to be too small for some, and just wasting space for all the other ones), just use pointers. // Martin
On 23/02/15 22:42, Martin Storsjö wrote: > On Mon, 23 Feb 2015, Luca Barbato wrote: > >> On 23/02/15 22:31, Martin Storsjö wrote: >>> This avoids allocating space for a too large buffer for all the >>> name strings. >>> --- >>> libavformat/rtpdec.c | 3 ++- >>> libavformat/rtpdec.h | 2 +- >>> 2 files changed, 3 insertions(+), 2 deletions(-) >>> >>> diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c >>> index f040ea6..d0b25bc 100644 >>> --- a/libavformat/rtpdec.c >>> +++ b/libavformat/rtpdec.c >>> @@ -113,7 +113,8 @@ RTPDynamicProtocolHandler >> *ff_rtp_handler_find_by_name(const char *name, >>> RTPDynamicProtocolHandler *handler; >>> for (handler = rtp_first_dynamic_payload_handler; >>> handler; handler = handler->next) >>> - if (!av_strcasecmp(name, handler->enc_name) && >>> + if (handler->enc_name && >>> + !av_strcasecmp(name, handler->enc_name) && >>> codec_type == handler->codec_type) >>> return handler; >>> return NULL; >>> diff --git a/libavformat/rtpdec.h b/libavformat/rtpdec.h >>> index 46b08ce..9f1a475 100644 >>> --- a/libavformat/rtpdec.h >>> +++ b/libavformat/rtpdec.h >>> @@ -113,7 +113,7 @@ typedef int >> (*DynamicPayloadPacketHandlerProc)(AVFormatContext *ctx, >>> int len, uint16_t >>> seq, int >> flags); >>> >>> struct RTPDynamicProtocolHandler { >>> - const char enc_name[50]; >>> + const char *enc_name; >>> enum AVMediaType codec_type; >>> enum AVCodecID codec_id; >>> int static_payload_id; /* 0 means no payload id is set. 0 is a >>> valid >>> >> >> Where is it allocated? > > They are just statically allocated const strings, like this in the structs: > .enc_name = "foo", > > So instead of preallocating a specific size for these (which either can > turn out to be too small for some, and just wasting space for all the > other ones), just use pointers. > Ok.
diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index f040ea6..d0b25bc 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -113,7 +113,8 @@ RTPDynamicProtocolHandler *ff_rtp_handler_find_by_name(const char *name, RTPDynamicProtocolHandler *handler; for (handler = rtp_first_dynamic_payload_handler; handler; handler = handler->next) - if (!av_strcasecmp(name, handler->enc_name) && + if (handler->enc_name && + !av_strcasecmp(name, handler->enc_name) && codec_type == handler->codec_type) return handler; return NULL; diff --git a/libavformat/rtpdec.h b/libavformat/rtpdec.h index 46b08ce..9f1a475 100644 --- a/libavformat/rtpdec.h +++ b/libavformat/rtpdec.h @@ -113,7 +113,7 @@ typedef int (*DynamicPayloadPacketHandlerProc)(AVFormatContext *ctx, int len, uint16_t seq, int flags); struct RTPDynamicProtocolHandler { - const char enc_name[50]; + const char *enc_name; enum AVMediaType codec_type; enum AVCodecID codec_id; int static_payload_id; /* 0 means no payload id is set. 0 is a valid