1/* 2 * Copyright 2008-2010 Stephan A��mus <superstippi@gmx.de> 3 * All rights reserved. Distributed under the terms of the MIT licensce. 4 */ 5 6 7#include "ProxyVideoSupplier.h" 8 9#include <stdio.h> 10#include <stdlib.h> 11#include <string.h> 12 13#include <Autolock.h> 14 15#include "VideoTrackSupplier.h" 16 17 18ProxyVideoSupplier::ProxyVideoSupplier() 19 : 20 fSupplierLock("video supplier lock"), 21 fSupplier(NULL) 22{ 23} 24 25 26ProxyVideoSupplier::~ProxyVideoSupplier() 27{ 28} 29 30 31const media_format& 32ProxyVideoSupplier::Format() const 33{ 34 return fSupplier->Format(); 35} 36 37 38status_t 39ProxyVideoSupplier::FillBuffer(int64 startFrame, void* buffer, 40 const media_raw_video_format& format, bool forceGeneration, 41 bool& wasCached) 42{ 43 bigtime_t now = system_time(); 44 45 BAutolock _(fSupplierLock); 46//printf("ProxyVideoSupplier::FillBuffer(%lld)\n", startFrame); 47 if (fSupplier == NULL) 48 return B_NO_INIT; 49 50 if (fSupplier->CurrentFrame() == startFrame + 1) { 51 wasCached = true; 52 return B_OK; 53 } 54 55 wasCached = false; 56 status_t ret = B_OK; 57 bigtime_t performanceTime = 0; 58 if (fSupplier->CurrentFrame() != startFrame) { 59 int64 frame = startFrame; 60 ret = fSupplier->SeekToFrame(&frame); 61 if (ret != B_OK) 62 return ret; 63 // Read frames until we reach the frame before the one we want to read. 64 // But don't do it for more than 5 frames, or we will take too much 65 // time. Doing it this way will still catch up to the next keyframe 66 // eventually (we may return the wrong frames until the next keyframe). 67 if (!forceGeneration && startFrame - frame > 5) 68 return B_TIMED_OUT; 69 while (frame < startFrame) { 70 ret = fSupplier->ReadFrame(buffer, &performanceTime, format, 71 wasCached); 72 if (ret != B_OK) 73 return ret; 74 frame++; 75 } 76 } 77 78 ret = fSupplier->ReadFrame(buffer, &performanceTime, format, wasCached); 79 80 fProcessingLatency = system_time() - now; 81 82 return ret; 83} 84 85 86void 87ProxyVideoSupplier::DeleteCaches() 88{ 89} 90 91 92void 93ProxyVideoSupplier::SetSupplier(VideoTrackSupplier* supplier) 94{ 95 BAutolock _(fSupplierLock); 96 97 fSupplier = supplier; 98} 99 100