btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / mediaplayer / supplier / ProxyVideoSupplier.cpp
blob1fc2d960ce83e4af8ba3d6dbd951f7461c225d4d
1 /*
2 * Copyright 2008-2010 Stephan Aßmus <superstippi@gmx.de>
3 * All rights reserved. Distributed under the terms of the MIT licensce.
4 */
7 #include "ProxyVideoSupplier.h"
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
13 #include <Autolock.h>
15 #include "VideoTrackSupplier.h"
18 ProxyVideoSupplier::ProxyVideoSupplier()
20 fSupplierLock("video supplier lock"),
21 fSupplier(NULL)
26 ProxyVideoSupplier::~ProxyVideoSupplier()
31 status_t
32 ProxyVideoSupplier::FillBuffer(int64 startFrame, void* buffer,
33 const media_raw_video_format& format, bool forceGeneration,
34 bool& wasCached)
36 bigtime_t now = system_time();
38 BAutolock _(fSupplierLock);
39 //printf("ProxyVideoSupplier::FillBuffer(%lld)\n", startFrame);
40 if (fSupplier == NULL)
41 return B_NO_INIT;
43 if (fSupplier->CurrentFrame() == startFrame + 1) {
44 wasCached = true;
45 return B_OK;
48 wasCached = false;
49 status_t ret = B_OK;
50 bigtime_t performanceTime = 0;
51 if (fSupplier->CurrentFrame() != startFrame) {
52 int64 frame = startFrame;
53 ret = fSupplier->SeekToFrame(&frame);
54 if (ret != B_OK)
55 return ret;
56 // Read frames until we reach the frame before the one we want to read.
57 // But don't do it for more than 5 frames, or we will take too much
58 // time. Doing it this way will still catch up to the next keyframe
59 // eventually (we may return the wrong frames until the next keyframe).
60 if (!forceGeneration && startFrame - frame > 5)
61 return B_TIMED_OUT;
62 while (frame < startFrame) {
63 ret = fSupplier->ReadFrame(buffer, &performanceTime, format,
64 wasCached);
65 if (ret != B_OK)
66 return ret;
67 frame++;
71 ret = fSupplier->ReadFrame(buffer, &performanceTime, format, wasCached);
73 fProcessingLatency = system_time() - now;
75 return ret;
79 void
80 ProxyVideoSupplier::DeleteCaches()
85 void
86 ProxyVideoSupplier::SetSupplier(VideoTrackSupplier* supplier)
88 BAutolock _(fSupplierLock);
90 fSupplier = supplier;