Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] Patch: avformat_index_get_entry and avformat_index_get_entry_from_timestamp const correctness
@ 2025-05-15 11:51 Martijn Otto
  2025-05-15 12:44 ` Andreas Rheinhardt
  0 siblings, 1 reply; 5+ messages in thread
From: Martijn Otto @ 2025-05-15 11:51 UTC (permalink / raw)
  To: ffmpeg-devel

[-- Attachment #1: Type: text/plain, Size: 150 bytes --]

With this patch it's now possible to call avformat_index_get_entry and
avformat_index_get_entry_from_timestamp with a const-qualified
AVStream. 


[-- Attachment #2: 0001-avformat_index_get_entry-and-_from_timestamp-const-c.patch --]
[-- Type: text/x-patch, Size: 3332 bytes --]

From cbf7880c230ccff35b8b6d1fab192a07c6083307 Mon Sep 17 00:00:00 2001
From: Martijn Otto <martijn@resolume.com>
Date: Mon, 7 Nov 2022 16:06:30 +0100
Subject: [PATCH] avformat_index_get_entry and *_from_timestamp const
 correctness

These functions don't need a mutable pointer to the stream, as they
don't modify anything, and only return const-qualified pointers
themselves.

Signed-off-by: Martijn Otto <martijn@resolume.com>
---
 libavformat/avformat.h | 4 ++--
 libavformat/internal.h | 2 +-
 libavformat/seek.c     | 8 ++++----
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 1d97d56ac5..aa216ca11e 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -2676,7 +2676,7 @@ int avformat_index_get_entries_count(const AVStream *st);
  *       until any function that takes the stream or the parent AVFormatContext
  *       as input argument is called.
  */
-const AVIndexEntry *avformat_index_get_entry(AVStream *st, int idx);
+const AVIndexEntry *avformat_index_get_entry(const AVStream *st, int idx);
 
 /**
  * Get the AVIndexEntry corresponding to the given timestamp.
@@ -2693,7 +2693,7 @@ const AVIndexEntry *avformat_index_get_entry(AVStream *st, int idx);
  *       until any function that takes the stream or the parent AVFormatContext
  *       as input argument is called.
  */
-const AVIndexEntry *avformat_index_get_entry_from_timestamp(AVStream *st,
+const AVIndexEntry *avformat_index_get_entry_from_timestamp(const AVStream *st,
                                                             int64_t wanted_timestamp,
                                                             int flags);
 /**
diff --git a/libavformat/internal.h b/libavformat/internal.h
index ce837fefc7..5931b1cf14 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -417,7 +417,7 @@ static av_always_inline FFStream *ffstream(AVStream *st)
 
 static av_always_inline const FFStream *cffstream(const AVStream *st)
 {
-    return (FFStream*)st;
+    return (const FFStream*)st;
 }
 
 #ifdef __GNUC__
diff --git a/libavformat/seek.c b/libavformat/seek.c
index a236e285c0..2db7ba0bd3 100644
--- a/libavformat/seek.c
+++ b/libavformat/seek.c
@@ -249,20 +249,20 @@ int avformat_index_get_entries_count(const AVStream *st)
     return cffstream(st)->nb_index_entries;
 }
 
-const AVIndexEntry *avformat_index_get_entry(AVStream *st, int idx)
+const AVIndexEntry *avformat_index_get_entry(const AVStream *st, int idx)
 {
-    const FFStream *const sti = ffstream(st);
+    const FFStream *const sti = cffstream(st);
     if (idx < 0 || idx >= sti->nb_index_entries)
         return NULL;
 
     return &sti->index_entries[idx];
 }
 
-const AVIndexEntry *avformat_index_get_entry_from_timestamp(AVStream *st,
+const AVIndexEntry *avformat_index_get_entry_from_timestamp(const AVStream *st,
                                                             int64_t wanted_timestamp,
                                                             int flags)
 {
-    const FFStream *const sti = ffstream(st);
+    const FFStream *const sti = cffstream(st);
     int idx = ff_index_search_timestamp(sti->index_entries,
                                         sti->nb_index_entries,
                                         wanted_timestamp, flags);
-- 
2.34.1


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] Patch: avformat_index_get_entry and avformat_index_get_entry_from_timestamp const correctness
  2025-05-15 11:51 [FFmpeg-devel] Patch: avformat_index_get_entry and avformat_index_get_entry_from_timestamp const correctness Martijn Otto
@ 2025-05-15 12:44 ` Andreas Rheinhardt
  2025-05-15 13:11   ` Martijn Otto
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Rheinhardt @ 2025-05-15 12:44 UTC (permalink / raw)
  To: ffmpeg-devel

Martijn Otto:
>  static av_always_inline const FFStream *cffstream(const AVStream *st)
>  {
> -    return (FFStream*)st;
> +    return (const FFStream*)st;
>  }

Your patch should be applied on top of git master, not some old version.
The above change is identical to 185d0acdc7a67b7d3d78d4c917334c4c3bf9accd.

Anyway, I remember that someone (IIRC Anton Khirnov) objected to the
const when this was introduced.

- Andreas

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] Patch: avformat_index_get_entry and avformat_index_get_entry_from_timestamp const correctness
  2025-05-15 12:44 ` Andreas Rheinhardt
@ 2025-05-15 13:11   ` Martijn Otto
  0 siblings, 0 replies; 5+ messages in thread
From: Martijn Otto @ 2025-05-15 13:11 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

[-- Attachment #1: Type: text/plain, Size: 1139 bytes --]

On Thu, 2025-05-15 at 14:44 +0200, Andreas Rheinhardt wrote:
> Martijn Otto:
> >  static av_always_inline const FFStream *cffstream(const AVStream
> > *st)
> >  {
> > -    return (FFStream*)st;
> > +    return (const FFStream*)st;
> >  }
> 
> Your patch should be applied on top of git master, not some old
> version.
> The above change is identical to
> 185d0acdc7a67b7d3d78d4c917334c4c3bf9accd.
> 
> Anyway, I remember that someone (IIRC Anton Khirnov) objected to the
> const when this was introduced.
> 
> - Andreas
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

I've updated the patch to apply to latest master, I've made it quite
some time in the past, and something went wrong with my submission
then.

I'm curious to hear what the arguments against these functions taking a
const-qualified stream are, given that we return a const-value and
don't modify it at all.

[-- Attachment #2: 0001-avformat_index_get_entry-and-_from_timestamp-const-c.patch --]
[-- Type: text/x-patch, Size: 2797 bytes --]

From 0c8f5873366e7721292007bca644ff5cc312df2b Mon Sep 17 00:00:00 2001
From: Martijn Otto <martijn@resolume.com>
Date: Thu, 15 May 2025 15:06:52 +0200
Subject: [PATCH] These functions don't need a mutable pointer to the stream,
 as they don't modify anything, and only return const-qualified pointers
 themselves.

---
 libavformat/avformat.h | 4 ++--
 libavformat/seek.c     | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 498c3020a5..5a0aa3f87d 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -2751,7 +2751,7 @@ int avformat_index_get_entries_count(const AVStream *st);
  *       until any function that takes the stream or the parent AVFormatContext
  *       as input argument is called.
  */
-const AVIndexEntry *avformat_index_get_entry(AVStream *st, int idx);
+const AVIndexEntry *avformat_index_get_entry(const AVStream *st, int idx);
 
 /**
  * Get the AVIndexEntry corresponding to the given timestamp.
@@ -2768,7 +2768,7 @@ const AVIndexEntry *avformat_index_get_entry(AVStream *st, int idx);
  *       until any function that takes the stream or the parent AVFormatContext
  *       as input argument is called.
  */
-const AVIndexEntry *avformat_index_get_entry_from_timestamp(AVStream *st,
+const AVIndexEntry *avformat_index_get_entry_from_timestamp(const AVStream *st,
                                                             int64_t wanted_timestamp,
                                                             int flags);
 /**
diff --git a/libavformat/seek.c b/libavformat/seek.c
index c0d94371e6..2308660638 100644
--- a/libavformat/seek.c
+++ b/libavformat/seek.c
@@ -254,20 +254,20 @@ int avformat_index_get_entries_count(const AVStream *st)
     return cffstream(st)->nb_index_entries;
 }
 
-const AVIndexEntry *avformat_index_get_entry(AVStream *st, int idx)
+const AVIndexEntry *avformat_index_get_entry(const AVStream *st, int idx)
 {
-    const FFStream *const sti = ffstream(st);
+    const FFStream *const sti = cffstream(st);
     if (idx < 0 || idx >= sti->nb_index_entries)
         return NULL;
 
     return &sti->index_entries[idx];
 }
 
-const AVIndexEntry *avformat_index_get_entry_from_timestamp(AVStream *st,
+const AVIndexEntry *avformat_index_get_entry_from_timestamp(const AVStream *st,
                                                             int64_t wanted_timestamp,
                                                             int flags)
 {
-    const FFStream *const sti = ffstream(st);
+    const FFStream *const sti = cffstream(st);
     int idx = ff_index_search_timestamp(sti->index_entries,
                                         sti->nb_index_entries,
                                         wanted_timestamp, flags);
-- 
2.47.2


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] Patch: avformat_index_get_entry and avformat_index_get_entry_from_timestamp const correctness
@ 2023-02-16  9:21 Martijn Otto
  0 siblings, 0 replies; 5+ messages in thread
From: Martijn Otto @ 2023-02-16  9:21 UTC (permalink / raw)
  To: ffmpeg-devel

[-- Attachment #1: Type: text/plain, Size: 146 bytes --]

With this patch it's now possible to call avformat_index_get_entry and
avformat_index_get_entry_from_timestamp with a const-qualified
AVStream. 


[-- Attachment #2: 0001-avformat_index_get_entry-and-_from_timestamp-const-c.patch --]
[-- Type: text/x-patch, Size: 3332 bytes --]

From cbf7880c230ccff35b8b6d1fab192a07c6083307 Mon Sep 17 00:00:00 2001
From: Martijn Otto <martijn@resolume.com>
Date: Mon, 7 Nov 2022 16:06:30 +0100
Subject: [PATCH] avformat_index_get_entry and *_from_timestamp const
 correctness

These functions don't need a mutable pointer to the stream, as they
don't modify anything, and only return const-qualified pointers
themselves.

Signed-off-by: Martijn Otto <martijn@resolume.com>
---
 libavformat/avformat.h | 4 ++--
 libavformat/internal.h | 2 +-
 libavformat/seek.c     | 8 ++++----
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 1d97d56ac5..aa216ca11e 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -2676,7 +2676,7 @@ int avformat_index_get_entries_count(const AVStream *st);
  *       until any function that takes the stream or the parent AVFormatContext
  *       as input argument is called.
  */
-const AVIndexEntry *avformat_index_get_entry(AVStream *st, int idx);
+const AVIndexEntry *avformat_index_get_entry(const AVStream *st, int idx);
 
 /**
  * Get the AVIndexEntry corresponding to the given timestamp.
@@ -2693,7 +2693,7 @@ const AVIndexEntry *avformat_index_get_entry(AVStream *st, int idx);
  *       until any function that takes the stream or the parent AVFormatContext
  *       as input argument is called.
  */
-const AVIndexEntry *avformat_index_get_entry_from_timestamp(AVStream *st,
+const AVIndexEntry *avformat_index_get_entry_from_timestamp(const AVStream *st,
                                                             int64_t wanted_timestamp,
                                                             int flags);
 /**
diff --git a/libavformat/internal.h b/libavformat/internal.h
index ce837fefc7..5931b1cf14 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -417,7 +417,7 @@ static av_always_inline FFStream *ffstream(AVStream *st)
 
 static av_always_inline const FFStream *cffstream(const AVStream *st)
 {
-    return (FFStream*)st;
+    return (const FFStream*)st;
 }
 
 #ifdef __GNUC__
diff --git a/libavformat/seek.c b/libavformat/seek.c
index a236e285c0..2db7ba0bd3 100644
--- a/libavformat/seek.c
+++ b/libavformat/seek.c
@@ -249,20 +249,20 @@ int avformat_index_get_entries_count(const AVStream *st)
     return cffstream(st)->nb_index_entries;
 }
 
-const AVIndexEntry *avformat_index_get_entry(AVStream *st, int idx)
+const AVIndexEntry *avformat_index_get_entry(const AVStream *st, int idx)
 {
-    const FFStream *const sti = ffstream(st);
+    const FFStream *const sti = cffstream(st);
     if (idx < 0 || idx >= sti->nb_index_entries)
         return NULL;
 
     return &sti->index_entries[idx];
 }
 
-const AVIndexEntry *avformat_index_get_entry_from_timestamp(AVStream *st,
+const AVIndexEntry *avformat_index_get_entry_from_timestamp(const AVStream *st,
                                                             int64_t wanted_timestamp,
                                                             int flags)
 {
-    const FFStream *const sti = ffstream(st);
+    const FFStream *const sti = cffstream(st);
     int idx = ff_index_search_timestamp(sti->index_entries,
                                         sti->nb_index_entries,
                                         wanted_timestamp, flags);
-- 
2.34.1


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] Patch: avformat_index_get_entry and avformat_index_get_entry_from_timestamp const correctness
@ 2022-11-07 15:11 Martijn Otto
  0 siblings, 0 replies; 5+ messages in thread
From: Martijn Otto @ 2022-11-07 15:11 UTC (permalink / raw)
  To: ffmpeg-devel

[-- Attachment #1: Type: text/plain, Size: 145 bytes --]

With this patch it's now possible to call avformat_index_get_entry and
avformat_index_get_entry_from_timestamp with a const-qualified
AVStream. 

[-- Attachment #2: 0001-avformat_index_get_entry-and-_from_timestamp-const-c.patch --]
[-- Type: text/x-patch, Size: 3332 bytes --]

From cbf7880c230ccff35b8b6d1fab192a07c6083307 Mon Sep 17 00:00:00 2001
From: Martijn Otto <martijn@resolume.com>
Date: Mon, 7 Nov 2022 16:06:30 +0100
Subject: [PATCH] avformat_index_get_entry and *_from_timestamp const
 correctness

These functions don't need a mutable pointer to the stream, as they
don't modify anything, and only return const-qualified pointers
themselves.

Signed-off-by: Martijn Otto <martijn@resolume.com>
---
 libavformat/avformat.h | 4 ++--
 libavformat/internal.h | 2 +-
 libavformat/seek.c     | 8 ++++----
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 1d97d56ac5..aa216ca11e 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -2676,7 +2676,7 @@ int avformat_index_get_entries_count(const AVStream *st);
  *       until any function that takes the stream or the parent AVFormatContext
  *       as input argument is called.
  */
-const AVIndexEntry *avformat_index_get_entry(AVStream *st, int idx);
+const AVIndexEntry *avformat_index_get_entry(const AVStream *st, int idx);
 
 /**
  * Get the AVIndexEntry corresponding to the given timestamp.
@@ -2693,7 +2693,7 @@ const AVIndexEntry *avformat_index_get_entry(AVStream *st, int idx);
  *       until any function that takes the stream or the parent AVFormatContext
  *       as input argument is called.
  */
-const AVIndexEntry *avformat_index_get_entry_from_timestamp(AVStream *st,
+const AVIndexEntry *avformat_index_get_entry_from_timestamp(const AVStream *st,
                                                             int64_t wanted_timestamp,
                                                             int flags);
 /**
diff --git a/libavformat/internal.h b/libavformat/internal.h
index ce837fefc7..5931b1cf14 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -417,7 +417,7 @@ static av_always_inline FFStream *ffstream(AVStream *st)
 
 static av_always_inline const FFStream *cffstream(const AVStream *st)
 {
-    return (FFStream*)st;
+    return (const FFStream*)st;
 }
 
 #ifdef __GNUC__
diff --git a/libavformat/seek.c b/libavformat/seek.c
index a236e285c0..2db7ba0bd3 100644
--- a/libavformat/seek.c
+++ b/libavformat/seek.c
@@ -249,20 +249,20 @@ int avformat_index_get_entries_count(const AVStream *st)
     return cffstream(st)->nb_index_entries;
 }
 
-const AVIndexEntry *avformat_index_get_entry(AVStream *st, int idx)
+const AVIndexEntry *avformat_index_get_entry(const AVStream *st, int idx)
 {
-    const FFStream *const sti = ffstream(st);
+    const FFStream *const sti = cffstream(st);
     if (idx < 0 || idx >= sti->nb_index_entries)
         return NULL;
 
     return &sti->index_entries[idx];
 }
 
-const AVIndexEntry *avformat_index_get_entry_from_timestamp(AVStream *st,
+const AVIndexEntry *avformat_index_get_entry_from_timestamp(const AVStream *st,
                                                             int64_t wanted_timestamp,
                                                             int flags)
 {
-    const FFStream *const sti = ffstream(st);
+    const FFStream *const sti = cffstream(st);
     int idx = ff_index_search_timestamp(sti->index_entries,
                                         sti->nb_index_entries,
                                         wanted_timestamp, flags);
-- 
2.34.1


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-05-15 13:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-15 11:51 [FFmpeg-devel] Patch: avformat_index_get_entry and avformat_index_get_entry_from_timestamp const correctness Martijn Otto
2025-05-15 12:44 ` Andreas Rheinhardt
2025-05-15 13:11   ` Martijn Otto
  -- strict thread matches above, loose matches on Subject: below --
2023-02-16  9:21 Martijn Otto
2022-11-07 15:11 Martijn Otto

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git