From 1853eee0f15d9d5a1ab0407d5d87e36167e5c9eb Mon Sep 17 00:00:00 2001
From: Kevin Kofler <kevin.kofler@chello.at>
Date: Sat, 23 Apr 2011 15:44:23 +0200
Subject: [PATCH] Prefer growisofs to wodim for DVD/BluRay burning.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

K3b 2 defaults to cdrecord for all burning tasks, including DVDs and BluRay
discs. Unfortunately, it also does this when cdrecord is actually wodim. This
is a bad idea, because wodim's DVD burning code is not the "ProDVD" code in
Jörg Schilling's current cdrecord releases, but a much older, buggier and
basically unmaintained DVD patch. We cannot ship the ProDVD code in wodim
because of licensing conflicts: That code was never released under the GPL, it
was relicensed directly from its original proprietary license to the CDDL. But
wodim is GPLed, and cannot be relicensed to the CDDL, in fact this was the
whole reason for the fork: Jörg Schilling's cdrecord distributes mixed CDDL and
GPL code linked together. So the DVD code in wodim is based on an ancient
experimental community-contributed DVD support patch for cdrecord (from the
times where ProDVD was entirely proprietary). So it's a bad idea to use wodim
for DVDs. As for BluRay discs, those aren't currently supported by wodim at
all; K3b should detect this, but still, it's better to explicitly default to
growisofs there too, in case wodim grows some experimental BluRay support.

One concrete known issue with wodim's DVD burning code is that it fails to burn
dual-layer DVD+Rs: https://bugzilla.redhat.com/show_bug.cgi?id=610976 . But
chances are there are many more DVD burning bugs in wodim, which are unlikely
to get fixed promptly.

Growisofs, on the other hand, is designed specifically for DVDs and BluRay
disks, doesn't have licensing issues and has been used successfully for DVDs
for years (in fact, K3b 1 always used growisofs for DVDs).

This patch makes K3b default to growisofs for all DVD or BluRay burning tasks
if cdrecord is actually wodim.

REVIEW: 101208
---
 libk3b/jobs/k3bdvdcopyjob.cpp         |   17 ++++++++++++-----
 libk3b/jobs/k3bmetawriter.cpp         |   12 ++++++++++--
 libk3b/projects/datacd/k3bdatajob.cpp |   13 ++++++++++---
 3 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/libk3b/jobs/k3bdvdcopyjob.cpp b/libk3b/jobs/k3bdvdcopyjob.cpp
index 5dff56b..3f15eb9 100644
--- a/libk3b/jobs/k3bdvdcopyjob.cpp
+++ b/libk3b/jobs/k3bdvdcopyjob.cpp
@@ -169,13 +169,20 @@ void K3b::DvdCopyJob::slotDiskInfoReady( K3b::Device::DeviceHandler* dh )
         // first let's determine which application to use
         d->usedWritingApp = writingApp();
         if ( d->usedWritingApp == K3b::WritingAppAuto ) {
-            // let's default to cdrecord for the time being
+            // prefer growisofs to wodim, which doesn't work all that great for DVDs
+            // (and doesn't support BluRay at all)
+            if ( k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "wodim" ) )
+                d->usedWritingApp = K3b::WritingAppGrowisofs;
+            // otherwise, let's default to cdrecord for the time being
             // FIXME: use growisofs for non-dao and non-auto mode
-            if ( K3b::Device::isBdMedia( d->sourceDiskInfo.mediaType() ) ) {
-                if ( k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "blu-ray" ) )
+            else {
+                if ( K3b::Device::isBdMedia( d->sourceDiskInfo.mediaType() ) ) {
+                    if ( k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "blu-ray" ) )
+                        d->usedWritingApp = K3b::WritingAppCdrecord;
+                    else
+                        d->usedWritingApp = K3b::WritingAppGrowisofs;
+                } else
                     d->usedWritingApp = K3b::WritingAppCdrecord;
-                else
-                    d->usedWritingApp = K3b::WritingAppGrowisofs;
             }
         }
 
diff --git a/libk3b/jobs/k3bmetawriter.cpp b/libk3b/jobs/k3bmetawriter.cpp
index 6338cd1..7d80e28 100644
--- a/libk3b/jobs/k3bmetawriter.cpp
+++ b/libk3b/jobs/k3bmetawriter.cpp
@@ -261,11 +261,13 @@ bool K3b::MetaWriter::determineUsedAppAndMode()
     bool cdrecordOnTheFly = false;
     bool cdrecordCdText = false;
     bool cdrecordBluRay = false;
+    bool cdrecordWodim = false;
     bool growisofsBluRay = false;
     if( k3bcore->externalBinManager()->binObject("cdrecord") ) {
         cdrecordOnTheFly = k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "audio-stdin" );
         cdrecordCdText = k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "cdtext" );
         cdrecordBluRay = k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "blu-ray" );
+        cdrecordWodim = k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "wodim" );
     }
     if( k3bcore->externalBinManager()->binObject("growisofs") ) {
         growisofsBluRay = k3bcore->externalBinManager()->binObject("growisofs")->hasFeature( "blu-ray" );
@@ -316,10 +318,16 @@ bool K3b::MetaWriter::determineUsedAppAndMode()
                 d->usedWritingApp = WritingAppGrowisofs;
             }
             else if( mediaType & Device::MEDIA_DVD_ALL ) {
-                d->usedWritingApp = WritingAppCdrecord;
+                // wodim (at least on fedora) doesn't do DVDs all that well, use growisofs instead
+                if ( cdrecordWodim ) {
+                    d->usedWritingApp = WritingAppGrowisofs;
+                }
+                else {
+                    d->usedWritingApp = WritingAppCdrecord;
+                }
             }
             else if( mediaType & Device::MEDIA_BD_ALL ) {
-                if( cdrecordBluRay ) {
+                if( cdrecordBluRay && ! cdrecordWodim ) {
                     d->usedWritingApp = WritingAppCdrecord;
                 }
                 else if( growisofsBluRay ) {
diff --git a/libk3b/projects/datacd/k3bdatajob.cpp b/libk3b/projects/datacd/k3bdatajob.cpp
index 3fb3abd..6af7f23 100644
--- a/libk3b/projects/datacd/k3bdatajob.cpp
+++ b/libk3b/projects/datacd/k3bdatajob.cpp
@@ -58,7 +58,7 @@ class K3b::DataJob::Private
 {
 public:
     Private()
-        : usedWritingApp(K3b::WritingAppCdrecord),
+        : usedWritingApp(K3b::WritingAppAuto),
           verificationJob( 0 ),
           pipe( 0 ) {
     }
@@ -813,8 +813,12 @@ bool K3b::DataJob::waitForBurnMedium()
 
         d->usedWritingApp = writingApp();
         // let's default to cdrecord for the time being (except for special cases below)
+        // but prefer growisofs to wodim for DVDs
         if ( d->usedWritingApp == K3b::WritingAppAuto ) {
-            d->usedWritingApp = K3b::WritingAppCdrecord;
+            if (k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "wodim" ))
+                d->usedWritingApp = K3b::WritingAppGrowisofs;
+            else
+                d->usedWritingApp = K3b::WritingAppCdrecord;
         }
 
         // -------------------------------
@@ -930,7 +934,10 @@ bool K3b::DataJob::waitForBurnMedium()
     else if ( foundMedium & K3b::Device::MEDIA_BD_ALL ) {
         d->usedWritingApp = writingApp();
         if( d->usedWritingApp == K3b::WritingAppAuto ) {
-            d->usedWritingApp = K3b::WritingAppCdrecord;
+            if (k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "wodim" ))
+                d->usedWritingApp = K3b::WritingAppGrowisofs;
+            else
+                d->usedWritingApp = K3b::WritingAppCdrecord;
         }
 
         if ( d->usedWritingApp == K3b::WritingAppCdrecord &&
-- 
1.7.10.4

