diff options
author | wm4 <wm4@nowhere> | 2019-09-29 01:39:17 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2019-09-29 01:41:19 +0200 |
commit | a604dc12be13af547572f18b9e09222eeda193c9 (patch) | |
tree | d8ebf6119415ed5dafa7996a0cfa4ed7265c4cf2 /common | |
parent | 2bb5ab07b7ee09fb7ae0e90a74c1e8e5adcc3d59 (diff) | |
download | mpv-a604dc12be13af547572f18b9e09222eeda193c9.tar.bz2 mpv-a604dc12be13af547572f18b9e09222eeda193c9.tar.xz |
recorder: don't use a magic index for mp_recorder_get_sink()
Although this was sort of elegant, it just seems to complicate things
slightly. Originally, the API meant that you cache mp_recorder_sink
yourself (which would avoid the mess of passing an index around), but
that too seems slightly roundabout.
In a later change, I want to change the set of streams passed to
mp_recorder_create(), and then I'd have to keep track of the index for
each stream, which would suck. With this commit, I can just pass the
unambiguous sh_stream to it, and it will be guaranteed to match the
correct stream.
The disadvantages are barely worth discussing. It's a new linear search
per packet, but usually only 2 to 4 streams are active at a time. Also,
in theory a user could want to write 2 streams using the same sh_stream
(same metadata, just writing different packets or so), but in practice
this is never done.
Diffstat (limited to 'common')
-rw-r--r-- | common/recorder.c | 14 | ||||
-rw-r--r-- | common/recorder.h | 3 |
2 files changed, 12 insertions, 5 deletions
diff --git a/common/recorder.c b/common/recorder.c index ad9c34e24c..1af736a71d 100644 --- a/common/recorder.c +++ b/common/recorder.c @@ -328,11 +328,17 @@ void mp_recorder_mark_discontinuity(struct mp_recorder *priv) } // Get a stream for writing. The pointer is valid until mp_recorder is -// destroyed. The stream is the index referencing the stream passed to -// mp_recorder_create(). -struct mp_recorder_sink *mp_recorder_get_sink(struct mp_recorder *r, int stream) +// destroyed. The stream ptr. is the same as one passed to +// mp_recorder_create() (returns NULL if it wasn't). +struct mp_recorder_sink *mp_recorder_get_sink(struct mp_recorder *r, + struct sh_stream *stream) { - return stream >= 0 && stream < r->num_streams ? r->streams[stream] : NULL; + for (int n = 0; n < r->num_streams; n++) { + struct mp_recorder_sink *rst = r->streams[n]; + if (rst->sh == stream) + return rst; + } + return NULL; } // Pass a packet to the given stream. The function does not own the packet, but diff --git a/common/recorder.h b/common/recorder.h index a6c8635c01..c0b1e36495 100644 --- a/common/recorder.h +++ b/common/recorder.h @@ -14,7 +14,8 @@ struct mp_recorder *mp_recorder_create(struct mpv_global *global, void mp_recorder_destroy(struct mp_recorder *r); void mp_recorder_mark_discontinuity(struct mp_recorder *r); -struct mp_recorder_sink *mp_recorder_get_sink(struct mp_recorder *r, int stream); +struct mp_recorder_sink *mp_recorder_get_sink(struct mp_recorder *r, + struct sh_stream *stream); void mp_recorder_feed_packet(struct mp_recorder_sink *s, struct demux_packet *pkt); |