Reference count for picture
bitstream_tell
Move bitstream write to a separate function, and add assertions about the part which should not write to bitstream.
Small changes to fix compiling on VS

- Added threads.h to VS project
- Included Windows.h in threads.h
Merge commit 'bf2c2a1330ce6eb093afe0c03eb3a99520a41e4b'