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 18 ProxyVideoSupplier::ProxyVideoSupplier() 19 : 20 fSupplierLock("video supplier lock"), 21 fSupplier(NULL) 22 { 23 } 24 25 26 ProxyVideoSupplier::~ProxyVideoSupplier() 27 { 28 } 29 30 31 status_t 32 ProxyVideoSupplier::FillBuffer(int64 startFrame, void* buffer, 33 const media_raw_video_format& format, bool forceGeneration, 34 bool& wasCached) 35 { 36 bigtime_t now = system_time(); 37 38 BAutolock _(fSupplierLock); 39 //printf("ProxyVideoSupplier::FillBuffer(%lld)\n", startFrame); 40 if (fSupplier == NULL) 41 return B_NO_INIT; 42 43 if (fSupplier->CurrentFrame() == startFrame + 1) { 44 wasCached = true; 45 return B_OK; 46 } 47 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++; 68 } 69 } 70 71 ret = fSupplier->ReadFrame(buffer, &performanceTime, format, wasCached); 72 73 fProcessingLatency = system_time() - now; 74 75 return ret; 76 } 77 78 79 void 80 ProxyVideoSupplier::DeleteCaches() 81 { 82 } 83 84 85 void 86 ProxyVideoSupplier::SetSupplier(VideoTrackSupplier* supplier) 87 { 88 BAutolock _(fSupplierLock); 89 90 fSupplier = supplier; 91 } 92 93