Commit 9b17bd17 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

mfmediaengine: Improve AddRange() behavior for intersecting ranges.

parent 4c610279
...@@ -653,13 +653,35 @@ static BOOL WINAPI time_range_ContainsTime(IMFMediaTimeRange *iface, double time ...@@ -653,13 +653,35 @@ static BOOL WINAPI time_range_ContainsTime(IMFMediaTimeRange *iface, double time
static HRESULT WINAPI time_range_AddRange(IMFMediaTimeRange *iface, double start, double end) static HRESULT WINAPI time_range_AddRange(IMFMediaTimeRange *iface, double start, double end)
{ {
struct time_range *range = impl_from_IMFMediaTimeRange(iface); struct time_range *range = impl_from_IMFMediaTimeRange(iface);
struct range *c;
size_t i;
TRACE("%p, %.8e, %.8e.\n", iface, start, end); TRACE("%p, %.8e, %.8e.\n", iface, start, end);
if (range->count) for (i = 0; i < range->count; ++i)
{ {
FIXME("Range merging is not implemented.\n"); c = &range->ranges[i];
return E_NOTIMPL;
/* New range is fully contained within existing one. */
if (c->start <= start && c->end >= end)
return S_OK;
/* New range fully contains existing one. */
if (c->start >= start && c->end <= end)
{
c->start = start;
c->end = end;
return S_OK;
}
/* Merge if ranges intersect. */
if ((start >= c->start && start <= c->end) ||
(end >= c->start && end <= c->end))
{
c->start = min(c->start, start);
c->end = max(c->end, end);
return S_OK;
}
} }
if (!mf_array_reserve((void **)&range->ranges, &range->capacity, range->count + 1, sizeof(*range->ranges))) if (!mf_array_reserve((void **)&range->ranges, &range->capacity, range->count + 1, sizeof(*range->ranges)))
......
...@@ -729,7 +729,6 @@ static void test_time_range(void) ...@@ -729,7 +729,6 @@ static void test_time_range(void)
ok(end == 1.0, "Unexpected end %.e.\n", end); ok(end == 1.0, "Unexpected end %.e.\n", end);
hr = IMFMediaTimeRange_AddRange(range, 2.0, 3.0); hr = IMFMediaTimeRange_AddRange(range, 2.0, 3.0);
todo_wine
ok(hr == S_OK, "Unexpected hr %#x.\n", hr); ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
count = IMFMediaTimeRange_GetLength(range); count = IMFMediaTimeRange_GetLength(range);
...@@ -737,49 +736,129 @@ todo_wine ...@@ -737,49 +736,129 @@ todo_wine
hr = IMFMediaTimeRange_GetStart(range, 0, &start); hr = IMFMediaTimeRange_GetStart(range, 0, &start);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr); ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
todo_wine
ok(start == 2.0, "Unexpected start %.8e.\n", start); ok(start == 2.0, "Unexpected start %.8e.\n", start);
hr = IMFMediaTimeRange_GetEnd(range, 0, &end); hr = IMFMediaTimeRange_GetEnd(range, 0, &end);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr); ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
todo_wine
ok(end == 3.0, "Unexpected end %.8e.\n", end); ok(end == 3.0, "Unexpected end %.8e.\n", end);
hr = IMFMediaTimeRange_AddRange(range, 10.0, 9.0); hr = IMFMediaTimeRange_AddRange(range, 10.0, 9.0);
todo_wine
ok(hr == S_OK, "Unexpected hr %#x.\n", hr); ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
count = IMFMediaTimeRange_GetLength(range); count = IMFMediaTimeRange_GetLength(range);
todo_wine
ok(count == 2, "Unexpected range count.\n"); ok(count == 2, "Unexpected range count.\n");
hr = IMFMediaTimeRange_GetStart(range, 0, &start); hr = IMFMediaTimeRange_GetStart(range, 0, &start);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr); ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
todo_wine
ok(start == 2.0, "Unexpected start %.8e.\n", start); ok(start == 2.0, "Unexpected start %.8e.\n", start);
hr = IMFMediaTimeRange_GetEnd(range, 0, &end); hr = IMFMediaTimeRange_GetEnd(range, 0, &end);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr); ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
todo_wine
ok(end == 3.0, "Unexpected end %.8e.\n", end); ok(end == 3.0, "Unexpected end %.8e.\n", end);
start = 0.0; start = 0.0;
hr = IMFMediaTimeRange_GetStart(range, 1, &start); hr = IMFMediaTimeRange_GetStart(range, 1, &start);
todo_wine {
ok(hr == S_OK, "Unexpected hr %#x.\n", hr); ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(start == 10.0, "Unexpected start %.8e.\n", start); ok(start == 10.0, "Unexpected start %.8e.\n", start);
}
hr = IMFMediaTimeRange_GetEnd(range, 1, &end); hr = IMFMediaTimeRange_GetEnd(range, 1, &end);
todo_wine {
ok(hr == S_OK, "Unexpected hr %#x.\n", hr); ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(end == 9.0, "Unexpected end %.8e.\n", end); ok(end == 9.0, "Unexpected end %.8e.\n", end);
}
hr = IMFMediaTimeRange_AddRange(range, 2.0, 9.1);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
count = IMFMediaTimeRange_GetLength(range);
ok(count == 2, "Unexpected range count.\n");
hr = IMFMediaTimeRange_GetStart(range, 0, &start);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(start == 2.0, "Unexpected start %.8e.\n", start);
hr = IMFMediaTimeRange_GetEnd(range, 0, &end);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(end == 9.1, "Unexpected end %.8e.\n", end);
hr = IMFMediaTimeRange_GetStart(range, 1, &start);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(start == 10.0, "Unexpected start %.8e.\n", start);
hr = IMFMediaTimeRange_GetEnd(range, 1, &end);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(end == 9.0, "Unexpected end %.8e.\n", end);
hr = IMFMediaTimeRange_AddRange(range, 8.5, 2.5);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
count = IMFMediaTimeRange_GetLength(range);
ok(count == 2, "Unexpected range count.\n");
hr = IMFMediaTimeRange_GetStart(range, 0, &start);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(start == 2.0, "Unexpected start %.8e.\n", start);
hr = IMFMediaTimeRange_GetEnd(range, 0, &end);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(end == 9.1, "Unexpected end %.8e.\n", end);
hr = IMFMediaTimeRange_AddRange(range, 20.0, 20.0);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
count = IMFMediaTimeRange_GetLength(range);
ok(count == 3, "Unexpected range count.\n");
hr = IMFMediaTimeRange_Clear(range); hr = IMFMediaTimeRange_Clear(range);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr); ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
count = IMFMediaTimeRange_GetLength(range); count = IMFMediaTimeRange_GetLength(range);
ok(!count, "Unexpected range count.\n"); ok(!count, "Unexpected range count.\n");
/* Intersect */
hr = IMFMediaTimeRange_AddRange(range, 5.0, 10.0);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
hr = IMFMediaTimeRange_AddRange(range, 6.0, 12.0);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
hr = IMFMediaTimeRange_GetStart(range, 0, &start);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(start == 5.0, "Unexpected start %.8e.\n", start);
hr = IMFMediaTimeRange_GetEnd(range, 0, &end);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(end == 12.0, "Unexpected end %.8e.\n", end);
count = IMFMediaTimeRange_GetLength(range);
ok(count == 1, "Unexpected range count.\n");
hr = IMFMediaTimeRange_AddRange(range, 4.0, 6.0);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
count = IMFMediaTimeRange_GetLength(range);
ok(count == 1, "Unexpected range count.\n");
hr = IMFMediaTimeRange_GetStart(range, 0, &start);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(start == 4.0, "Unexpected start %.8e.\n", start);
hr = IMFMediaTimeRange_GetEnd(range, 0, &end);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(end == 12.0, "Unexpected end %.8e.\n", end);
hr = IMFMediaTimeRange_AddRange(range, 5.0, 3.0);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
count = IMFMediaTimeRange_GetLength(range);
ok(count == 1, "Unexpected range count.\n");
hr = IMFMediaTimeRange_GetStart(range, 0, &start);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(start == 4.0, "Unexpected start %.8e.\n", start);
hr = IMFMediaTimeRange_GetEnd(range, 0, &end);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(end == 12.0, "Unexpected end %.8e.\n", end);
IMFMediaTimeRange_Release(range); IMFMediaTimeRange_Release(range);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment