| 46 | | long access = 0; |
|---|
| 47 | | |
|---|
| 48 | | if(flags & URL_RDWR) { |
|---|
| 49 | | access = kDataHCanRead | kDataHCanWrite; |
|---|
| 50 | | } else if(flags & URL_WRONLY) { |
|---|
| 51 | | access = kDataHCanWrite; |
|---|
| 52 | | } else { |
|---|
| 53 | | access = kDataHCanRead; |
|---|
| 54 | | } |
|---|
| 55 | | |
|---|
| 56 | | private = h->priv_data; |
|---|
| 57 | | result = OpenAComponent(GetDataHandler(private->dataRef, private->dataRefType, access), &private->dh); |
|---|
| 58 | | require_noerr(result,bail); |
|---|
| 59 | | |
|---|
| 60 | | result = DataHSetDataRef(private->dh, private->dataRef); |
|---|
| 61 | | require_noerr(result,bail); |
|---|
| 62 | | |
|---|
| 63 | | if(access & kDataHCanRead) { |
|---|
| 64 | | result = DataHOpenForRead(private->dh); |
|---|
| 65 | | require_noerr(result,bail); |
|---|
| 66 | | } |
|---|
| 67 | | if(access & kDataHCanWrite) { |
|---|
| 68 | | result = DataHOpenForWrite(private->dh); |
|---|
| 69 | | require_noerr(result,bail); |
|---|
| 70 | | } |
|---|
| 71 | | |
|---|
| 72 | | private->pos = 0ll; |
|---|
| 73 | | private->size = 0ll; |
|---|
| 74 | | |
|---|
| 75 | | result = DataHGetFileSize64(private->dh, &fsize); |
|---|
| | 42 | ComponentResult result = DataHGetFileSize64(private->dh, &fsize); |
|---|
| 87 | | |
|---|
| 88 | | bail: |
|---|
| 89 | | return result; |
|---|
| | 54 | bail: |
|---|
| | 55 | return result; |
|---|
| | 56 | } |
|---|
| | 57 | |
|---|
| | 58 | /* !!! THIS FUNCTION ASSUMES h->priv_data IS VALID in contrary to the other open functions |
|---|
| | 59 | * found in ffmpeg */ |
|---|
| | 60 | static int dataref_open(URLContext *h, const char *filename, int flags) |
|---|
| | 61 | { |
|---|
| | 62 | ComponentResult result; |
|---|
| | 63 | dataref_private *private; |
|---|
| | 64 | long access = 0; |
|---|
| | 65 | |
|---|
| | 66 | if(flags & URL_RDWR) { |
|---|
| | 67 | access = kDataHCanRead | kDataHCanWrite; |
|---|
| | 68 | } else if(flags & URL_WRONLY) { |
|---|
| | 69 | access = kDataHCanWrite; |
|---|
| | 70 | } else { |
|---|
| | 71 | access = kDataHCanRead; |
|---|
| | 72 | } |
|---|
| | 73 | |
|---|
| | 74 | private = h->priv_data; |
|---|
| | 75 | result = OpenAComponent(GetDataHandler(private->dataRef, private->dataRefType, access), &private->dh); |
|---|
| | 76 | require_noerr(result,bail); |
|---|
| | 77 | |
|---|
| | 78 | result = DataHSetDataRef(private->dh, private->dataRef); |
|---|
| | 79 | require_noerr(result,bail); |
|---|
| | 80 | |
|---|
| | 81 | if(access & kDataHCanRead) { |
|---|
| | 82 | result = DataHOpenForRead(private->dh); |
|---|
| | 83 | require_noerr(result,bail); |
|---|
| | 84 | } |
|---|
| | 85 | if(access & kDataHCanWrite) { |
|---|
| | 86 | result = DataHOpenForWrite(private->dh); |
|---|
| | 87 | require_noerr(result,bail); |
|---|
| | 88 | } |
|---|
| | 89 | |
|---|
| | 90 | private->pos = 0ll; |
|---|
| | 91 | private->size = 0ll; |
|---|
| | 92 | |
|---|
| | 93 | result = dataref_update_filesize(private); |
|---|
| | 94 | require_noerr(result,bail); |
|---|
| | 95 | bail: |
|---|
| | 96 | return result; |
|---|
| 95 | | int64_t read; |
|---|
| 96 | | |
|---|
| 97 | | dataref_private *p = (dataref_private*)h->priv_data; |
|---|
| 98 | | |
|---|
| 99 | | read = p->size - p->pos; |
|---|
| 100 | | read = (read < size) ? read : size; |
|---|
| | 102 | dataref_private *p = (dataref_private*)h->priv_data; |
|---|
| | 103 | int read; |
|---|
| | 104 | |
|---|
| | 105 | if (p->pos + size > p->size) { |
|---|
| | 106 | // it tried to read past the end |
|---|
| | 107 | // but since we cache the size, it might be wrong |
|---|
| | 108 | // try to update the size before clipping the request |
|---|
| | 109 | dataref_update_filesize(p); |
|---|
| | 110 | } |
|---|
| | 111 | |
|---|
| | 112 | if (p->pos >= p->size) |
|---|
| | 113 | return 0; // can't read past the end |
|---|
| | 114 | else |
|---|
| | 115 | read = FFMIN(size, p->size - p->pos); |
|---|