# HG changeset patch # User reimar # Date 1289411028 0 # Node ID 4157eca9694732683af84f13f5076bfd5863e9ea # Parent 0624fa95a2aa139af429d808d296a9d2622cf720 Support reading larger blocks in one go for bd:// protocol. diff -r 0624fa95a2aa -r 4157eca96947 stream/stream_bd.c --- a/stream/stream_bd.c Wed Nov 10 17:21:28 2010 +0000 +++ b/stream/stream_bd.c Wed Nov 10 17:43:48 2010 +0000 @@ -276,9 +276,7 @@ static off_t bd_read(struct bd_priv *bd, uint8_t *buf, int len) { int read_len; - // TODO: would be nicer if this function also worked for larger reads - int max_len = BD_UNIT_SIZE - (bd->pos % BD_UNIT_SIZE); - len = FFMIN(len, max_len); + int unit_offset = bd->pos % BD_UNIT_SIZE; len &= ~15; if (!len) return 0; @@ -287,10 +285,14 @@ if (read_len != len) return -1; - if (bd->pos % BD_UNIT_SIZE) { - // decrypt in place - av_aes_crypt(bd->aescbc, buf, buf, len / 16, bd->iv.u8, 1); - } else { + if (unit_offset) { + int decrypt_len = BD_UNIT_SIZE - unit_offset; + av_aes_crypt(bd->aescbc, buf, buf, decrypt_len / 16, bd->iv.u8, 1); + buf += decrypt_len; + len -= decrypt_len; + } + while (len) { + int decrypt_len = FFMIN(len, BD_UNIT_SIZE); // reset aes context as at start of unit key enc_seed; bd->iv = BD_CBC_IV; @@ -307,7 +309,9 @@ // decrypt av_aes_crypt(bd->aescbc, &buf[16], &buf[16], - (len - 16) / 16, bd->iv.u8, 1); + (decrypt_len - 16) / 16, bd->iv.u8, 1); + buf += decrypt_len; + len -= decrypt_len; } bd->pos += read_len; @@ -461,6 +465,7 @@ bd->device = DEFAULT_BD_DEVICE; s->sector_size = BD_UNIT_SIZE; + s->read_chunk = 32 * BD_UNIT_SIZE; s->flags = STREAM_READ | MP_STREAM_SEEK; s->fill_buffer = bd_stream_fill_buffer; s->seek = bd_stream_seek;