[vlc-devel] [PATCH 2/3] demux: adaptive: fix segment compare
Zhao Zhili
quinkblack at foxmail.com
Sun Dec 17 16:54:35 CET 2017
> On 16 Dec 2017, at 11:12 PM, Zhao Zhili <quinkblack at foxmail.com> wrote:
>
> ---
> modules/demux/adaptive/playlist/Segment.cpp | 21 ++++++++++++---------
> 1 file changed, 12 insertions(+), 9 deletions(-)
>
> diff --git a/modules/demux/adaptive/playlist/Segment.cpp b/modules/demux/adaptive/playlist/Segment.cpp
> index b0cc2d8..38cb412 100644
> --- a/modules/demux/adaptive/playlist/Segment.cpp
> +++ b/modules/demux/adaptive/playlist/Segment.cpp
> @@ -143,18 +143,21 @@ int ISegment::compare(ISegment *other) const
> {
> if(duration.Get())
> {
> - stime_t diff = startTime.Get() - other->startTime.Get();
> - if(diff)
> - return diff / diff;
> + if(startTime.Get() > other->startTime.Get())
> + return 1;
> + else if(startTime.Get() < other->startTime.Get())
> + return -1;
> }
>
> - size_t diff = startByte - other->startByte;
> - if(diff)
> - return diff / diff;
> + if(startByte > other->startByte)
> + return 1;
> + else if(startByte < other->startByte)
> + return -1;
>
> - diff = endByte - other->endByte;
> - if(diff)
> - return diff / diff;
> + if(endByte > other->endByte)
> + return 1;
> + else if(endByte < other->endByte)
> + return -1;
>
> return 0;
> }
> --
> 2.7.4
>
The original implementation is a little confusion, especially the diff/diff part. Does it mean 1 literally or does it mean diff/llabs(diff) and is a typo?
And the latter doesn't work for the size_t. The patch is my try to guess.
More information about the vlc-devel
mailing list