summaryrefslogtreecommitdiffstats
path: root/media-libs/taglib/files/taglib-1.11-ds-rusxmms.patch
blob: 9f777c8d52421a956c61aca292392e46759b0b92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
diff -dPNur taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/config.h.cmake taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/config.h.cmake
--- taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/config.h.cmake	2018-10-28 14:43:45.000000000 +0100
+++ taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/config.h.cmake	2019-09-01 08:32:29.569443643 +0200
@@ -30,6 +30,9 @@
 /* Indicates whether debug messages are shown even in release mode */
 #cmakedefine   TRACE_IN_RELEASE 1
 
+/* Defined if you have LibRCC from RusXMMS project */
+#cmakedefine   HAVE_LIBRCC 1
+
 #cmakedefine TESTS_DIR "@TESTS_DIR@"
 
 #endif
diff -dPNur taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/ConfigureChecks.cmake taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/ConfigureChecks.cmake
--- taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/ConfigureChecks.cmake	2018-10-28 14:43:45.000000000 +0100
+++ taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/ConfigureChecks.cmake	2019-09-01 08:32:29.577443787 +0200
@@ -213,3 +213,5 @@
 if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
 	set(PLATFORM WINRT 1)
 endif()
+
+SET(HAVE_LIBRCC 1)
\ No newline at end of file
diff -dPNur taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/examples/tagreader_c.c taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/examples/tagreader_c.c
--- taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/examples/tagreader_c.c	2018-10-28 14:43:45.000000000 +0100
+++ taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/examples/tagreader_c.c	2019-09-01 08:32:29.577443787 +0200
@@ -38,7 +38,7 @@
   TagLib_Tag *tag;
   const TagLib_AudioProperties *properties;
 
-  taglib_set_strings_unicode(FALSE);
+  //taglib_set_strings_unicode(FALSE);
 
   for(i = 1; i < argc; i++) {
     printf("******************** \"%s\" ********************\n", argv[i]);
diff -dPNur taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/examples/tagwriter.cpp taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/examples/tagwriter.cpp
--- taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/examples/tagwriter.cpp	2018-10-28 14:43:45.000000000 +0100
+++ taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/examples/tagwriter.cpp	2019-09-01 08:32:29.577443787 +0200
@@ -115,7 +115,7 @@
     if(isArgument(argv[i]) && i + 1 < argc && !isArgument(argv[i + 1])) {
 
       char field = argv[i][1];
-      TagLib::String value = argv[i + 1];
+      TagLib::String value(argv[i + 1], TagLib::String::Locale);
 
       TagLib::List<TagLib::FileRef>::ConstIterator it;
       for(it = fileList.begin(); it != fileList.end(); ++it) {
diff -dPNur taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/CMakeLists.txt taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/CMakeLists.txt
--- taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/CMakeLists.txt	2018-10-28 14:43:45.000000000 +0100
+++ taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/CMakeLists.txt	2019-09-01 08:32:29.577443787 +0200
@@ -41,6 +41,7 @@
   audioproperties.h
   taglib_export.h
   ${CMAKE_CURRENT_BINARY_DIR}/../taglib_config.h
+  toolkit/rccpatch.h
   toolkit/taglib.h
   toolkit/tstring.h
   toolkit/tlist.h
@@ -312,6 +313,7 @@
 )
 
 set(toolkit_SRCS
+  toolkit/rccpatch.cpp
   toolkit/tstring.cpp
   toolkit/tstringlist.cpp
   toolkit/tbytevector.cpp
@@ -354,7 +356,9 @@
 add_library(tag ${tag_LIB_SRCS} ${tag_HDRS})
 
 if(HAVE_ZLIB AND NOT HAVE_ZLIB_SOURCE)
-  target_link_libraries(tag ${ZLIB_LIBRARIES})
+  target_link_libraries(tag rcc ${ZLIB_LIBRARIES})
+else ()
+  target_link_libraries(tag rcc)
 endif()
 
 set_target_properties(tag PROPERTIES
diff -dPNur taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/mpeg/id3v1/id3v1tag.cpp taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/mpeg/id3v1/id3v1tag.cpp
--- taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/mpeg/id3v1/id3v1tag.cpp	2018-10-28 14:43:45.000000000 +0100
+++ taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/mpeg/id3v1/id3v1tag.cpp	2019-09-01 08:32:29.577443787 +0200
@@ -69,15 +69,18 @@
 
 String ID3v1::StringHandler::parse(const ByteVector &data) const
 {
-  return String(data, String::Latin1).stripWhiteSpace();
+  return String(data, String::Latin1ID3).stripWhiteSpace();
 }
 
 ByteVector ID3v1::StringHandler::render(const String &s) const
 {
-  if(s.isLatin1())
-    return s.data(String::Latin1);
-  else
+  if(!s.isLatin1())
+  {
+   if (String::ID3WType(String::Latin1) == String::Latin1)
     return ByteVector();
+  }
+
+  return s.data(String::Latin1ID3);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -262,7 +265,7 @@
     d->track   = static_cast<unsigned char>(data[offset + 29]);
   }
   else
-    d->comment = data.mid(offset, 30);
+    d->comment = stringHandler->parse(data.mid(offset, 30));
 
   offset += 30;
 
diff -dPNur taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/mpeg/id3v2/frames/commentsframe.cpp taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/mpeg/id3v2/frames/commentsframe.cpp
--- taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/mpeg/id3v2/frames/commentsframe.cpp	2018-10-28 14:43:45.000000000 +0100
+++ taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/mpeg/id3v2/frames/commentsframe.cpp	2019-09-01 08:32:29.578443805 +0200
@@ -150,10 +150,10 @@
     return;
   }
 
-  d->textEncoding = String::Type(data[0]);
+  d->textEncoding = String::ID3Type(data[0]);
   d->language = data.mid(1, 3);
 
-  int byteAlign = d->textEncoding == String::Latin1 || d->textEncoding == String::UTF8 ? 1 : 2;
+  int byteAlign = (d->textEncoding == String::Latin1 || d->textEncoding == String::Latin1ID3 || d->textEncoding == String::Latin1ID3V2 || d->textEncoding == String::UTF8) ? 1 : 2;
 
   ByteVectorList l = ByteVectorList::split(data.mid(4), textDelimiter(d->textEncoding), byteAlign, 2);
 
@@ -173,11 +173,13 @@
   ByteVector v;
 
   String::Type encoding = d->textEncoding;
+  
+  encoding = String::ID3WType(encoding);
 
   encoding = checkTextEncoding(d->description, encoding);
   encoding = checkTextEncoding(d->text, encoding);
 
-  v.append(char(encoding));
+  v.append(char(String::ID3RealType(encoding)));
   v.append(d->language.size() == 3 ? d->language : "XXX");
   v.append(d->description.data(encoding));
   v.append(textDelimiter(encoding));
diff -dPNur taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/mpeg/id3v2/frames/textidentificationframe.cpp taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/mpeg/id3v2/frames/textidentificationframe.cpp
--- taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/mpeg/id3v2/frames/textidentificationframe.cpp	2018-10-28 14:43:45.000000000 +0100
+++ taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/mpeg/id3v2/frames/textidentificationframe.cpp	2019-09-01 08:32:29.578443805 +0200
@@ -191,12 +191,12 @@
 
   // read the string data type (the first byte of the field data)
 
-  d->textEncoding = String::Type(data[0]);
+  d->textEncoding = String::ID3Type(data[0]);
 
   // split the byte array into chunks based on the string type (two byte delimiter
   // for unicode encodings)
 
-  int byteAlign = d->textEncoding == String::Latin1 || d->textEncoding == String::UTF8 ? 1 : 2;
+  int byteAlign = (d->textEncoding == String::Latin1 || d->textEncoding == String::Latin1ID3 || d->textEncoding == String::Latin1ID3V2 || d->textEncoding == String::UTF8) ? 1 : 2;
 
   // build a small counter to strip nulls off the end of the field
 
@@ -227,11 +227,14 @@
 
 ByteVector TextIdentificationFrame::renderFields() const
 {
-  String::Type encoding = checkTextEncoding(d->fieldList, d->textEncoding);
+  String::Type encoding = d->textEncoding;
+  
+  encoding = String::ID3WType(encoding);
+  encoding = checkTextEncoding(d->fieldList, encoding);
 
   ByteVector v;
 
-  v.append(char(encoding));
+  v.append(char(String::ID3RealType(encoding)));
 
   for(StringList::ConstIterator it = d->fieldList.begin(); it != d->fieldList.end(); it++) {
 
diff -dPNur taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/mpeg/id3v2/id3v2frame.cpp taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/mpeg/id3v2/id3v2frame.cpp
--- taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/mpeg/id3v2/id3v2frame.cpp	2018-10-28 14:43:45.000000000 +0100
+++ taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/mpeg/id3v2/id3v2frame.cpp	2019-09-01 08:32:29.578443805 +0200
@@ -297,7 +297,7 @@
   if((encoding == String::UTF8 || encoding == String::UTF16BE) && version != 4)
     return String::UTF16;
 
-  if(encoding != String::Latin1)
+  if((encoding != String::Latin1)&&(encoding != String::Latin1ID3V2))
     return encoding;
 
   for(StringList::ConstIterator it = fields.begin(); it != fields.end(); ++it) {
diff -dPNur taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/toolkit/rccpatch.cpp taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/toolkit/rccpatch.cpp
--- taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/toolkit/rccpatch.cpp	1970-01-01 01:00:00.000000000 +0100
+++ taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/toolkit/rccpatch.cpp	2019-09-01 08:32:29.578443805 +0200
@@ -0,0 +1,237 @@
+#include <stdlib.h>
+
+#include <string>
+#include "tstring.h"
+#include "tbytevector.h"
+
+//#define RCC_DEBUG
+
+
+#ifndef HAVE_LIBRCC
+# include <config.h>
+#endif
+
+#ifdef HAVE_LIBRCC
+# ifdef RCC_DEBUG
+#  include <stdio.h>
+# endif /* RCC_DEBUG */
+# include <librcc.h>
+# include <string.h>
+#endif /* HAVE_LIBRCC */
+
+
+#ifdef HAVE_LIBRCC
+# define ID3_CLASS 0
+# define ID3V2_CLASS 1
+# define UTF_CLASS 2
+# define OUT_CLASS 3
+static rcc_class classes[] = {
+    { "id3", RCC_CLASS_STANDARD, NULL, NULL, "ID3 Encoding", 0 },
+    { "id3v2", RCC_CLASS_STANDARD, "id3", NULL, "ID3 v.2 Encoding", 0 },
+    { "utf", RCC_CLASS_KNOWN, "UTF-8", NULL, "Unicode Encoding", 0},
+    { "out", RCC_CLASS_TRANSLATE_LOCALE, "LC_CTYPE", NULL, "Output Encoding", 0 },
+    { NULL, RCC_CLASS_STANDARD, NULL, NULL, NULL, 0 }
+};
+
+static int rcc_initialized = 0;
+
+static rcc_context ctx = NULL;
+#endif /* HAVE_LIBRCC */
+
+
+void rccTaglibPatchFree() {
+#ifdef HAVE_LIBRCC
+    if (rcc_initialized) {
+       rccFree();
+       rcc_initialized = 0;
+    }
+#endif /* HAVE_LIBRCC */
+}
+
+void rccTaglibPatchInit() {
+#ifdef HAVE_LIBRCC
+    if (rcc_initialized) return;
+    rccInit();
+    rccInitDefaultContext(NULL, 0, 0, classes, 0);
+    rccLoad(NULL, "xmms");
+    rccInitDb4(NULL, NULL, 0);
+    rcc_initialized = 1;
+#endif /* HAVE_LIBRCC */
+}
+
+void rccTaglibPatchSetContext(void *newctx) {
+#ifdef HAVE_LIBRCC
+    if (newctx) {
+	ctx = (rcc_context)newctx;
+	rcc_initialized = 1;
+    }
+#endif /* HAVE_LIBRCC */
+}
+
+static void rccTaglibPatchTryInit() {
+#ifdef HAVE_LIBRCC
+    if (!rcc_initialized) {
+	rccTaglibPatchInit();
+	if (rcc_initialized) atexit(rccTaglibPatchFree);	
+    }
+#endif /* HAVE_LIBRCC */
+}
+
+
+TagLib::ByteVector rccTaglibPatchRecodeOutput(const std::string &s) {
+    TagLib::ByteVector v;
+#ifdef HAVE_LIBRCC
+    size_t rlen;
+    char *res;
+
+    rccTaglibPatchTryInit();
+
+    res = rccSizedRecode(ctx, UTF_CLASS, OUT_CLASS, s.c_str(), s.length(), &rlen);
+#ifdef RCC_DEBUG
+    for (const unsigned char *c = (const unsigned char*)s.c_str(); *c; c++) {
+	if (*c > 127) {
+	    printf(" Output: %s - %s\n", s.c_str(), res?res:"null");
+	    break;
+	}
+    }
+#endif /* RCC_DEBUG */
+
+    if (res) v.setData(res, rlen);
+    else v.setData("", 0);
+    //v.setData(s.c_str(), s.length());
+
+    return v;
+#else
+    v.setData("", 0);
+    
+    return v;
+#endif /* HAVE_LIBRCC */
+}
+
+TagLib::ByteVector rccTaglibPatchRecodeOutputID3(const std::string &s, bool v2 = false) {
+    TagLib::ByteVector v;
+#ifdef HAVE_LIBRCC
+    size_t rlen;
+    char *res;
+
+    rccTaglibPatchTryInit();
+
+    res = rccSizedRecode(ctx, UTF_CLASS, v2?ID3V2_CLASS:ID3_CLASS, s.c_str(), s.length(), &rlen);
+#ifdef RCC_DEBUG
+    for (const unsigned char *c = (const unsigned char*)s.c_str(); *c; c++) {
+	if (*c > 127) {
+	    printf(" OutputID3(%i): %s - %s\n", v2, s.c_str(), res?res:"null");
+	    break;
+	}
+    }
+#endif /* RCC_DEBUG */
+
+    if (res) v.setData(res, rlen);
+    else v.setData("", 0);
+    //v.setData(s.c_str(), s.length());
+
+    return v;
+#else
+    v.setData("", 0);
+    
+    return v;
+#endif /* HAVE_LIBRCC */
+}
+
+TagLib::ByteVector rccTaglibPatchRecodeInput(const std::string &s) {
+    TagLib::ByteVector v;
+#ifdef HAVE_LIBRCC
+    size_t rlen;
+    char *res;
+
+    rccTaglibPatchTryInit();
+
+    res = rccSizedRecode(ctx, OUT_CLASS, UTF_CLASS, s.c_str(), s.length(), &rlen);
+#ifdef RCC_DEBUG
+    for (const unsigned char *c = (const unsigned char*)s.c_str(); *c; c++) {
+	if (*c > 127) {
+	    printf(" Input: %s - %s\n", s.c_str(), res?res:"null");
+	    break;
+	}
+    }
+#endif /* RCC_DEBUG */
+
+    if (res) v.setData(res, rlen);
+    else
+#endif /* HAVE_LIBRCC */
+    v.setData("", 0);
+    
+    return v;
+}
+
+TagLib::ByteVector rccTaglibPatchRecodeInputID3(const std::string &s, bool v2 = false) {
+    TagLib::ByteVector v;
+#ifdef HAVE_LIBRCC
+    size_t rlen;
+    char *res;
+
+    rccTaglibPatchTryInit();
+
+    res = rccSizedRecode(ctx, v2?ID3V2_CLASS:ID3_CLASS, UTF_CLASS, s.c_str(), s.length(), &rlen);
+#ifdef RCC_DEBUG
+    for (const unsigned char *c = (const unsigned char*)s.c_str(); *c; c++) {
+	if (*c > 127) {
+	    printf(" InputID3(%i): %s - %s\n", v2, s.c_str(), res?res:"null");
+	    break;
+	}
+    }
+#endif /* RCC_DEBUG */
+    if (res) v.setData(res, rlen + 1);
+    else
+#endif /* HAVE_LIBRCC */
+    v.setData("", 0);
+
+    return v;
+}
+
+TagLib::String::Type rccTaglibPatchGetLocaleType() {
+#ifdef HAVE_LIBRCC
+    size_t len;
+    char charset[32];
+
+    rccTaglibPatchTryInit();
+    if (!rccLocaleGetCharset(charset, NULL, 31)) {
+	if (!strncmp(charset, "UTF", 3)) {
+	    len = strlen(charset);
+	    
+	    if (charset[len-1]=='8') return TagLib::String::UTF8;
+	    if (!strcmp(charset+(len-2),"16")) return TagLib::String::UTF16;
+	    if (!strcmp(charset+(len-4),"16LE")) return TagLib::String::UTF16LE;
+	    if (!strcmp(charset+(len-4),"16BE")) return TagLib::String::UTF16BE;
+	}
+	return TagLib::String::Latin1;
+    }
+#endif /* HAVE_LIBRCC */
+    return TagLib::String::UTF8;
+}
+
+TagLib::String::Type rccTaglibPatchGetID3Type() {
+#ifdef HAVE_LIBRCC
+    size_t len;
+    const char *charset;
+
+    rccTaglibPatchTryInit();
+    
+    charset = rccGetCurrentCharsetName(ctx, ID3V2_CLASS);
+    if (charset) {
+	if (!strncmp(charset, "UTF", 3)) {
+	    len = strlen(charset);
+	    
+	    if (charset[len-1]=='8') return TagLib::String::UTF8;
+	    if (!strcmp(charset+(len-2),"16")) return TagLib::String::UTF16;
+	    if (!strcmp(charset+(len-4),"16LE")) return TagLib::String::UTF16LE;
+	    if (!strcmp(charset+(len-4),"16BE")) return TagLib::String::UTF16BE;
+	}
+	return TagLib::String::Latin1ID3V2;
+    } else {
+	// Error or no-language configured: If Latin1ID3V2 is returned we normally will use the default unicode encoding unless Latin1 is selected by taglib
+	return TagLib::String::Latin1ID3V2;
+    }
+#endif /* HAVE_LIBRCC */
+    return TagLib::String::Latin1;
+}
diff -dPNur taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/toolkit/rccpatch.h taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/toolkit/rccpatch.h
--- taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/toolkit/rccpatch.h	1970-01-01 01:00:00.000000000 +0100
+++ taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/toolkit/rccpatch.h	2019-09-01 08:32:29.578443805 +0200
@@ -0,0 +1,20 @@
+#ifndef _RCC_PATCH_H
+#define _RCC_PATCH_H
+
+#include <string.h>
+#include "tstring.h"
+#include "tbytevector.h"
+
+void rccTaglibPatchFree();
+void rccTaglibPatchInit();
+void rccTaglibPatchSetContext(void *newctx);
+
+TagLib::ByteVector rccTaglibPatchRecodeOutput(const std::string &s);
+TagLib::ByteVector rccTaglibPatchRecodeInput(const std::string &s);
+TagLib::ByteVector rccTaglibPatchRecodeOutputID3(const std::string &s, bool v2 = false);
+TagLib::ByteVector rccTaglibPatchRecodeInputID3(const std::string &s, bool v2 = false);
+
+TagLib::String::Type rccTaglibPatchGetLocaleType();
+TagLib::String::Type rccTaglibPatchGetID3Type();
+
+#endif /* _RCC_PATCH_H */
diff -dPNur taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/toolkit/tstring.cpp taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/toolkit/tstring.cpp
--- taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/toolkit/tstring.cpp	2018-10-28 14:43:45.000000000 +0100
+++ taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/toolkit/tstring.cpp	2019-09-01 08:27:18.763821274 +0200
@@ -33,6 +33,7 @@
 #include <trefcounter.h>
 #include <tutils.h>
 
+#include "rccpatch.h"
 #include "tstring.h"
 
 namespace
@@ -48,16 +49,6 @@
       return String::UTF16BE;
   }
 
-  // Converts a Latin-1 string into UTF-16(without BOM/CPU byte order)
-  // and copies it to the internal buffer.
-  void copyFromLatin1(std::wstring &data, const char *s, size_t length)
-  {
-    data.resize(length);
-
-    for(size_t i = 0; i < length; ++i)
-      data[i] = static_cast<unsigned char>(s[i]);
-  }
-
   // Converts a UTF-8 string into UTF-16(without BOM/CPU byte order)
   // and copies it to the internal buffer.
   void copyFromUTF8(std::wstring &data, const char *s, size_t length)
@@ -73,6 +64,36 @@
       debug("String::copyFromUTF8() - UTF8-CPP error: " + message);
       data.clear();
     }
+
+  }
+
+  // Converts a Latin-1 string into UTF-16(without BOM/CPU byte order)
+  // and copies it to the internal buffer.
+  void copyFromLatin1(std::wstring &data, const char *s, size_t length, bool prepare, String::Type t)
+  {
+     // librcc conversation
+    if (prepare) {
+      ByteVector v;
+      std::string std_s(s);
+
+      if (t == String::Latin1ID3) v = rccTaglibPatchRecodeInputID3(std_s, false);
+      else if (t == String::Latin1ID3V2) v = rccTaglibPatchRecodeInputID3(std_s, true);
+      else /* Latin1 converted from Locale */ v = rccTaglibPatchRecodeInput(std_s);
+
+      if (v.size()) {
+        copyFromUTF8(data, v.data(), v.size());
+        return;
+      } else {
+	// We don't know if we got UTF-8 encoded string or either rcc is disable or something is failed,
+	// since standard applications are really expecting here Latin1, it is safe to just check if we have violations of UTF8
+	//if (Unicode::isLegalUTF8(s)) t = UTF8;
+      } 
+    }
+
+    data.resize(length);
+
+    for(size_t i = 0; i < length; ++i)
+      data[i] = static_cast<unsigned char>(s[i]);
   }
 
   // Helper functions to read a UTF-16 character from an array.
@@ -175,8 +196,11 @@
 String::String(const std::string &s, Type t) :
   d(new StringPrivate())
 {
+  if(t == Locale)
+    t = rccTaglibPatchGetLocaleType();
+
   if(t == Latin1)
-    copyFromLatin1(d->data, s.c_str(), s.length());
+    copyFromLatin1(d->data, s.c_str(), s.length(), true, t);
   else if(t == String::UTF8)
     copyFromUTF8(d->data, s.c_str(), s.length());
   else {
@@ -223,8 +247,11 @@
 String::String(const char *s, Type t) :
   d(new StringPrivate())
 {
-  if(t == Latin1)
-    copyFromLatin1(d->data, s, ::strlen(s));
+  if(t == Locale)
+    t = rccTaglibPatchGetLocaleType();
+
+  if(t == Latin1 || t == Latin1ID3 || t == Latin1ID3V2)
+    copyFromLatin1(d->data, s, ::strlen(s), true, t);
   else if(t == String::UTF8)
     copyFromUTF8(d->data, s, ::strlen(s));
   else {
@@ -245,8 +272,11 @@
 String::String(char c, Type t) :
   d(new StringPrivate())
 {
-  if(t == Latin1)
-    copyFromLatin1(d->data, &c, 1);
+  if(t == Locale)
+    t = rccTaglibPatchGetLocaleType();
+
+  if(t == Latin1 || t == Latin1ID3 || t == Latin1ID3V2)
+    copyFromLatin1(d->data, &c, 1, true, t);
   else if(t == String::UTF8)
     copyFromUTF8(d->data, &c, 1);
   else {
@@ -260,8 +290,11 @@
   if(v.isEmpty())
     return;
 
-  if(t == Latin1)
-    copyFromLatin1(d->data, v.data(), v.size());
+  if(t == Locale)
+    t = rccTaglibPatchGetLocaleType();
+
+  if(t == Latin1 || t == Latin1ID3 || t == Latin1ID3V2)
+    copyFromLatin1(d->data, v.data(), v.size(), true, t);
   else if(t == UTF8)
     copyFromUTF8(d->data, v.data(), v.size());
   else
@@ -416,8 +449,38 @@
 
 ByteVector String::data(Type t) const
 {
-  switch(t)
-  {
+  ByteVector v;
+
+  if (t == Locale) {
+        // The source is either Unicode or real Latin1 (if rcc is bypassed)
+    std::string s = to8Bit(true);
+
+        // In case of UTF8 locale, this probably will return NULL (no recoding needed), but we will take UTF8 path in the next swtich
+    v = rccTaglibPatchRecodeOutput(s);
+    if (v.size()) return v;
+
+    t = rccTaglibPatchGetLocaleType();
+  }
+
+  switch(t) {
+  case Latin1ID3:
+  case Latin1ID3V2:
+    {
+      std::string s = to8Bit(true);
+      if (t == Latin1ID3) v = rccTaglibPatchRecodeOutputID3(s, false);
+      else if (t == Latin1ID3V2) v = rccTaglibPatchRecodeOutputID3(s, true);
+      if (v.size()) 
+        return v;
+      
+          // we don't know if we got NULL because rcc is disabled (error) or UTF8 output is required
+      if ((t == Latin1ID3V2)&&(rccTaglibPatchGetID3Type() == UTF8)) {
+          v.setData(s.c_str(), s.length());
+      } else {
+          for(wstring::const_iterator it = d->data.begin(); it != d->data.end(); it++)
+            v.append(char(*it));
+      }
+      return v;
+    }
   case Latin1:
     {
       ByteVector v(size(), 0);
@@ -741,7 +804,33 @@
 
 std::ostream &operator<<(std::ostream &s, const TagLib::String &str)
 {
-  s << str.to8Bit();
+  TagLib::ByteVector bv = str.data(TagLib::String::Locale);
+  s << bv;
   return s;
 }
 
+TagLib::String::Type TagLib::String::ID3Type(int i)
+{
+  if(i == Latin1)
+    return Latin1ID3V2;
+  return Type(i);
+};
+
+TagLib::String::Type TagLib::String::ID3WType(Type type)
+{
+  Type rcc_type = rccTaglibPatchGetID3Type();
+  if((rcc_type == Latin1ID3)||(rcc_type == Latin1ID3V2)||(rcc_type == Latin1)) {
+    if(type == Latin1) return
+      rcc_type;
+    return type;
+  }
+
+  return rcc_type;
+};
+
+TagLib::String::Type TagLib::String::ID3RealType(Type type)
+{
+  if((type == Latin1ID3) || (type == Latin1ID3V2))
+    return Latin1;
+  return type;
+}
diff -dPNur taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/toolkit/tstring.h taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/toolkit/tstring.h
--- taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c/taglib/toolkit/tstring.h	2018-10-28 14:43:45.000000000 +0100
+++ taglib-5cb589a5b82c13ba8f0542e5e79629da7645cb3c-ds/taglib/toolkit/tstring.h	2019-09-01 08:32:29.579443823 +0200
@@ -96,6 +96,18 @@
      */
     enum Type {
       /*!
+       * Determine using current locale settings
+       */
+      Locale = -1,
+      /*!
+       * Latin1 for ID3 tags.
+       */
+      Latin1ID3 = 65,
+      /*!
+       * Latin1 for ID3v2 tags.
+       */
+      Latin1ID3V2 = 66,
+      /*!
        * IS08859-1, or <i>Latin1</i> encoding.  8 bit characters.
        */
       Latin1 = 0,
@@ -117,6 +129,10 @@
        */
       UTF16LE = 4
     };
+    
+    static Type ID3Type(int i);
+    static Type ID3WType(Type type);
+    static Type ID3RealType(Type type);
 
     /*!
      * Constructs an empty String.