Use FAB subtitler's rather odd DFC -> frame rate mapping.
[libsub.git] / src / stl_binary_writer.cc
index 1e85b8105ed1e04a8e6f3928a0e72746c25febbe..9b98b84cf7de4fe3888045384e3d407d20876cbd 100644 (file)
@@ -20,6 +20,7 @@
 #include "stl_binary_writer.h"
 #include "subtitle.h"
 #include "iso6937.h"
+#include "stl_util.h"
 #include "compose.hpp"
 #include <boost/locale.hpp>
 #include <list>
@@ -111,6 +112,7 @@ sub::write_stl_binary (
        assert (editor_contact_details.size() <= 32);
        
        char* buffer = new char[1024];
+       memset (buffer, 0, 1024);
        ofstream output (file_name.string().c_str ());
        STLBinaryTables tables;
 
@@ -154,7 +156,7 @@ sub::write_stl_binary (
        /* Code page: 850 */
        put_string (buffer + 0, "850");
        /* Disk format code */
-       put_string (buffer + 3, String::compose ("STL%1.01", rint (frames_per_second)));
+       put_string (buffer + 3, stl_frame_rate_to_dfc (frames_per_second));
        /* Display standard code: open subtitling */
        put_string (buffer + 11, "0");
        /* Character code table: Latin (ISO 6937) */
@@ -176,7 +178,7 @@ sub::write_stl_binary (
        /* Total number of subtitles */
        put_int_as_string (buffer + 243, subtitles.size (), 5);
        /* Total number of subtitle groups */
-       put_string (buffer + 248, "000");
+       put_string (buffer + 248, "001");
        /* Maximum number of displayable characters in any text row */
        put_int_as_string (buffer + 251, longest, 2);
        /* Maximum number of displayable rows */
@@ -201,12 +203,16 @@ sub::write_stl_binary (
        int N = 0;
        for (list<Subtitle>::const_iterator i = subtitles.begin(); i != subtitles.end(); ++i) {
 
+               memset (buffer, 0, 1024);
+
                /* Subtitle group number */
-               put_int_as_int (buffer + 0, 0, 1);
+               put_int_as_int (buffer + 0, 1, 1);
                /* Subtitle number */
                put_int_as_int (buffer + 1, N, 2);
-               /* Extension block number */
-               put_int_as_int (buffer + 3, 0, 1);
+               /* Extension block number.  Use 0xff here to indicate that it is the last TTI
+                  block in this subtitle "set", as we only ever use one.
+               */
+               put_int_as_int (buffer + 3, 255, 1);
                /* Cumulative status */
                put_int_as_int (buffer + 4, tables.cumulative_status_enum_to_file (CUMULATIVE_STATUS_NOT_CUMULATIVE), 1);
                /* Time code in */